可以在項目上使用一些幫助。我的表看起來是這樣的:VBA Excel找到值旁邊的第一個空單元格
WEEK1 TEST1價值
WEEK1 TEST1 [空白]
WEEK1 TEST2 [空白]
WEEK2 TEST1價值
WEEK2 TEST2 [空白]
WEEK2 TEST1價值
大約800行這些在不同的變化。
現在我需要找到C中第一個具有WEEK2和TEST2的空單元。如何去做這件事?目的是在該單元格中輸入來自定義A和B的用戶表單的值。
可以在項目上使用一些幫助。我的表看起來是這樣的:VBA Excel找到值旁邊的第一個空單元格
WEEK1 TEST1價值
WEEK1 TEST1 [空白]
WEEK1 TEST2 [空白]
WEEK2 TEST1價值
WEEK2 TEST2 [空白]
WEEK2 TEST1價值
大約800行這些在不同的變化。
現在我需要找到C中第一個具有WEEK2和TEST2的空單元。如何去做這件事?目的是在該單元格中輸入來自定義A和B的用戶表單的值。
Sub FindMatch()
Dim sTxt1 As String, sTxt2 As String, vMatch As Variant
sTxt1 = """Week2"""
sTxt2 = """Test2"""
sformula = "MATCH(1,(A:A=" & sTxt1 & ")*(B:B=" & sTxt2 & "),0)"
vMatch = Evaluate(sformula)
If IsNumeric(vMatch) Then MsgBox Range("C" & vMatch).Address
End Sub
添加另一個條件檢查列-C是否爲空?替換下面的代碼行以驗證列C部分。
sformula = "MATCH(1,(A:A=" & sTxt1 & ")*(B:B=" & sTxt2 & ")*(C:C=""""),0)"
試試此代碼。
Sub CheckRows()
Dim RowNo As Long
RowNo = 1
With ActiveWorkbook.Sheets(1)
Do While .Cells(RowNo, 1).Value <> ""
If UCase(.Cells(RowNo, 1).Value) = "WEEK2" And _
UCase(.Cells(RowNo, 2).Value) = "TEST2" And _
.Cells(RowNo, 3).Value = "" Then
MsgBox "Found at Row Number " & RowNo
Exit Sub
Else
RowNo = RowNo + 1
End If
Loop
End With
End Sub
Sub test()
Dim x As Range, i&: i = [C:C].Find("*", , , , , xlPrevious).Row
For Each x In Range("A1:A" & i)
If UCase(x.Value2 & x.Offset(, 1).Value2 & _
x.Offset(, 2).Value2) = "WEEK2TEST2" Then
MsgBox x.Offset(, 2).Address(0, 0): Exit For
End If
Next x
End Sub
謝謝,但此人不考慮如果C是不是空白,只是發現MATHES A&B – user2446928
完美,謝謝你的第一個! – user2446928