我在一列单元格中有一组参考数据(它可能是一行,但无论如何)。
我想检查几个工作表,检查选定的值范围,如果当前单元格值在参考数据中,则将其用作粘贴到下一系列单元格的偏移量中的值,直到当前单元格更改为某个参考数据中的新值,此时应为新值和下一系列单元格重复粘贴过程。例如
Sub doStuff()
Dim RefRange As Range, queryRange As Range, checkCell As Rnage
String pasteDate As String
Set RefRange = Range("A1:A50")
Set queryRange = .Selected
For Each checkCell In queryRange
If checkCell.Value IN RefRange <***here's where I don't know what to use ***>
pasteData = checkCell.Value
' Advance to next item
Next
ElseIf checkCell.Value Not In queryRange <***here's where I don't know what to use ***>
ActiveCell.Offset(0,+1).Value = pasteData
End If
Next
End Sub
我知道如何在 SQL 中执行此操作,VBA 中是否有类似的方法?
在 SQL 中:
Select a, b from table where c in ('foo', 'bar', 'baz') OR
Select a, b from table where c in (select e from some_other_table)
TIA