您是否試圖檢查Y列中的每個單元格是否來自另一個工作表的列表。 vlookup函數的結果總是「false」。我不知道爲什麼。請指教VBA需要檢查Y列中的每個單元格是否來自另一個工作表的列表
Sub CheckDropDown()
Dim MyStringVar As Variant, i As Integer
Dim Lookup_Range As Range, lastRow As Integer, ws As Worksheet
Set Lookup_Range = Worksheets("Lists").Range("C1:C21")
lastRow = Cells.Find("*", [A1], , , xlByRows, xlPrevious).row
For i = 2 To lastRow
On Error Resume Next
'MyStringVar = ActiveCell.FormulaR1C1 = "=VLOOKUP(Cells(i,25),Lists!C[-25],1)"
MyStringVar = ActiveCell.Formula = "VLookup(Cells(i, 25).value, Lookup_Range, 1, False)"
On Error GoTo 0
Select Case Cells(i, 25).value
Case IsEmpty(MyStringVar)
' do nothing
Case Is = MyStringVar
Case Is <> MyStringVar
ActiveSheet.Cells(i, 25).Interior.Color = RGB(255, 255, 5)
End Select
Next i
End Sub
需要從引號除去任何VBA:'ActiveCell.Formula = 「VLOOKUP(」 &細胞(I,25)。地址(0,0)& 「」 &Lookup_Range.address(1, 1)&「,1,False)」' –