シゴトで新しいExceVBAを書くことになり、他のExcelファイル内から指定した文字列を含むセルを全て選択状態にするマクロを作っているのですが…うまくいきませんorz
同一ブック内なら問題なく動く上、他のブック内の処理でも数字に関しては思ったとおりの動きをしてくれるのに、なぜか文字列に対してはFindメソッドが言うことを聞いてくれません。(´・ω・`)
コードは以下のとおり。
わかる人誰かたすけてクダサイ… orz
・ThisWorkbook内
Option Explicit
Public Sub Start()
Load SearchForm
SearchForm.CheckBox1.Value = True
SearchForm.CheckBox2.Value = True
SearchForm.Show
End Sub
Private Sub Workbook_Open()
Call Start
End Sub
・Sheet1内
Option Explicit
Private Sub CommandButton1_Click() ‘検索 ボタン
Dim strFText As String ‘検索文字
Dim strRange As String ‘見つけたセル
Dim blnCase, blnByte As Boolean ‘検索オプション
Dim rngFCell As Range, strFAddr As String
‘値の取得
strFText = Me.TextBox1.Value
blnCase = Me.CheckBox1.Value
blnByte = Me.CheckBox2.Value
strRange = ""
‘検索文字が空欄の場合は処理中断
If strFText = "" Then Exit Sub
‘
‘検索開始
Set rngFCell = ActiveWorkbook.ActiveSheet.Cells.Find(strFText, , xlValues, xlWhole, xlByRows, xlNext, blnCase, blnByte, False)
If rngFCell Is Nothing Then
MsgBox ("Nothing")
Exit Sub
End If
strFAddr = rngFCell.Address ‘開始位置判別用
‘シート内の検索条件に一致するセルを全て検索する
Do
‘見つけたセルのアドレスを変数に格納(あとで使う)
strRange = strRange & rngFCell.Address & ","
‘次を検索
Set rngFCell = Cells.FindNext(rngFCell)
‘全て検索し終えたら検索を終了する
If rngFCell.Address = strFAddr Then Exit Do
Loop
‘セルのアドレスを整形
strRange = Left(strRange, Len(strRange) – 1)
strRange = Replace(strRange, "$", "")
‘セルを全て選択状態にする
Application.ActiveSheet.Range(strRange).Select
Exit Sub
End Sub
Private Sub CommandButton2_Click() ‘閉じる ボタン
Unload Me
End Sub
Private Sub UserForm_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
‘フォームをダブルクリックしたらフォームのサイズを変更する
If Me.Height = 225.75 Then
Me.Height = 50
Else
Me.Height = 225.75
End If
End Sub