識別に使用されるコードの塊が与えられましたExcelワークシート内の二重引用符など。このコードは、メッセージボックス内の二重引用符の1つのインスタンスを示しており、すべてのインスタンスを表示するようにしています。以下は、指定したものからの抜粋です。私は引用の複数のインスタンスを表示することを望んで変数を繰り返してみましたが、これまでのところ運はありません。
Option Explicit
Sub BadCHARFinder()
"Finds any occurance of: Quotes (single or double, Underscore, Hyphen, Carot in the excel sheet
"Note: skips the header row when searching
"Find Double Quote (")
Dim foundDoubleQuote As Variant
Set foundDoubleQuote = ActiveSheet.Cells.Find("""", ActiveSheet.Cells(2, 1), xlValues, xlPart)
If (Not foundDoubleQuote Is Nothing) Then
"found
MsgBox "Found double quote at: " & foundDoubleQuote.Address, vbOKOnly, "foundDoubleQuote"
Else
"not found
End If
End Sub
回答:
回答№1は2Range.FindNextがあなたが探しているものであるように、あなたは正しい次のものを見つける必要があります。下記は、すべてのアドレスをループして取得する方法です。
Option Explicit
Sub BadCHARFinder()
"Finds any occurance of: Quotes (single or double, Underscore, Hyphen, Carot in the excel sheet
"Note: skips the header row when searching
"Find Double Quote (")
Dim foundDoubleQuote As Variant
Dim allCellAddresses As String
Dim firstCellAddress As String
Set foundDoubleQuote = ActiveSheet.Cells.Find("""", ActiveSheet.Cells(1, 1), xlValues, xlPart, xlByRows)
If (Not foundDoubleQuote Is Nothing) Then
"capture the first cell address or we end up in an endless loop
firstCellAddress = foundDoubleQuote.Address
Do
"add the address of the cell to our string of cells
allCellAddresses = allCellAddresses + vbCrLf + foundDoubleQuote.Address
"find the next cell with the data
Set foundDoubleQuote = ActiveSheet.Cells.FindNext(foundDoubleQuote)
"keep going until we find the first address we started with
Loop While foundDoubleQuote.Address <> firstCellAddress
"inform user
MsgBox "Found double quote at: " & allCellAddresses, vbOKOnly, "foundDoubleQuote"
Else
"not found
End If
End Sub