A1 = Orange
B1:B5 = My Data
If B1:B5 = Red, Blue, or Green, display the value from A1
谢谢你的帮助!
2 回答
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
2 回答
我've adapted @Davesexcel '的决议,检查一下:How to avoid using select in VBA for variable cell ranges?
RonDeBruin的这个决议也很好:
http://www.rondebruin.nl/win/s9/win006.htm
将您的值放在列中的某个位置:
那么C1中的一个简单公式:
如果找到匹配,则返回其行号 . If测试它是数字还是错误 . 如果是数字,则找到匹配并返回A1中的值 . 否则返回一个空字符串 .