我正在尝试编写一个公式,如果一系列单元格等于列表中特定的值,它将返回一个单元格的值。
例如:
A1 = Orange
B1:B5 = My Data
If B1:B5 = Red, Blue, or Green, display the value from A1
感谢您的帮助!
答案 0 :(得分:0)
Dim a as Range, listValues() as string 'array of string
Dim str as string, i as integer
str = "Red;Blue;Green"
listValues = Split(str,";") 'split str using ";"
for i= Lbound(listValues) to Ubound(listValues) 'loop thru the array
Set a = ActiveSheet.UsedRange.Find(what:=listValues(i), lookat:=xlWhole)
if Not a Is Nothing Then
'value found
a.value = Range("A1").value
end if
next i
我已经改编了@Davesexcel的决议,检查一下: How to avoid using select in VBA for variable cell ranges?
RonDeBruin的这个决议也很好:
答案 1 :(得分:0)