![](/img/trans.png)
[英]Excel COUNTIFS cell equals range of cells AND cell from range equals another range
[英]Excel - if a range of cells equals a value from a list I want to populate the value of another cell
我正在嘗試編寫一個公式,如果一系列單元格等於列表中特定的值,則該公式將返回一個單元格的值。
例如:
A1 = Orange
B1:B5 = My Data
If B1:B5 = Red, Blue, or Green, display the value from A1
謝謝你的幫助!
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 的分辨率,請檢查他的分辨率: 如何避免在 VBA 中使用 select 來處理可變單元格范圍?
RonDeBruin 的這個決議也很好:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.