2つの列の文字列比較を実行します。実行時エラー '424' MatchData(item1.Row)= item2.Valueでオブジェクトが必要です
第1列のデータと第2列のデータを比較します。一致がある場合、私はこのコードを実行すると、列1
に2列目からのデータを記述する必要が、私は
実行時エラー「424」オブジェクトが
を必要に出くわしました
行MatchData(item1.Row) = item2.Value
。
この行にコメントすると、このエラーメッセージは表示されません。
Private Sub CommandButton2_Click()
Dim attr1 As Range, data1 As Range
Dim item1, item2, item3, lastRow, lastRow2
Dim UsrInput, UsrInput2 As Variant
Dim Cnt As Integer, LineCnt As Integer
Dim MatchData(1 To 9000) As String
Dim i As Integer
For i = 1 To 9000
MatchData(i) = ""
Next i
UsrInput = InputBox("Enter Atribute Column")
UsrInput2 = InputBox("Enter Column Alphabet to compare")
With ActiveSheet
lastRow = .Cells(.Rows.Count, UsrInput).End(xlUp).Row
'MsgBox lastRow
End With
With ActiveSheet
lastRow = .Cells(.Rows.Count, UsrInput2).End(xlUp).Row
'MsgBox lastRow
End With
Set attr1 = Range(UsrInput & "2:" & UsrInput & lastRow)
Set data1 = Range(UsrInput2 & "2:" & UsrInput2 & lastRow)
For Each item1 In attr1
item1.Value = Replace(item1.Value, " ", "")
Next item1
For Each item1 In attr1
If item1 = "" Then Exit For
item1 = "*" & item1 & "*"
For Each item2 In data1
If item2 Like item1 Then
MatchData(item1.Row) = item2.Value
MatchData(item2.Row) = item2.Value
Debug.Print "Match"
'Debug.Print item2.Row
Debug.Print item1.Row
Debug.Print item1
Debug.Print item2
Debug.Print " "
End If
Next item2
Next item1
End Sub
問題は、あなたが 'セットMatchData(item1.Row)= item2.Value'にそれを変更した場合離れて行くのか? – jsheeran
あなたは 'item1.Row'が存在することを確信していますか?エラーボックスが表示されたら、「デバッグ」を押し、ローカルウィンドウを使用して 'item1'を調べます。 – AlexP
MatchDataは文字列としてDim'dされるため、 MatchData(item2.Row)= CStr(item2.Value) – Tragamor