スペースの予測不可能な外観ので、あなたは、より良い、「unspaced」の文字列を渡すカスタムMyMatch()
機能によってそれらをaltoghether無視したい:
を次のように
Function MyMatch(textToSearch As String, rng As Range) As Long
Dim txtRng As Range, cell As Range
MyMatch = -1 '<--| default value for no match found
On Error Resume Next
Set txtRng = rng.SpecialCells(xlCellTypeConstants, xlTextValues) '<--| consider only cells with text values
On Error GoTo 0
If Not txtRng Is Nothing Then '<--| If there's at least one cell with text value
For Each cell In txtRng '<--| loop through selected "text" cells
If WorksheeyFunction.Substitute (cell.Value, " ", "") = textToSearch Then '<--|remove every space occurrence from cell value and compare it to your "nospace" searched value
MyMatch = cell.Column - rng.Columns(1).Column + 1
Exit For
End If
Next cell
End If
End With
を使用するには
Dim StateProvince As Long
StateProvince = MyMatch("State/Province", hr.Sheets("Open").Rows(1)) '<--| pass an "unspaced" string to search
If StateProvince > 0 Then
' code for handling found StateProvince
Else
' code for handling NOT found StateProvince
End If
最初の条件が見つからない場合、私はエラーを取得し、スペース –
と同じ、私はERを与えるVBAでワークシート関数を使用して、それらのエラーを持つ可能 –
トラップなどのような動的コードを作成しようとしていますそれでもし第1にエラーがあれば第2を、第2をスキップしてください。または、ワイルドカードを使用する* –