提问人:Karl Cachia 提问时间:11/20/2022 最后编辑:GSergKarl Cachia 更新时间:11/21/2022 访问量:212
索引匹配 VBA 以更新行
Index Match VBA to update on rows
问:
我有这个代码,我希望它在下一行工作,直到最后一行,
Sub Index_Match()
Dim result As Variant
Range("P3").Value = [INDEX('Sheet1'!K:K,MATCH(1,(L3='Sheet1'!G:G)\*(Q3='Sheet1'!J:J),0))]
Debug.Print result
End Sub
代码必须在每一行上更新。
Range("P4").Value = [INDEX('Sheet1'!K:K,MATCH(1,(L4='Sheet1'!G:G)\*(Q4='Sheet1'!J:J),0))]
等等.....
任何帮助表示赞赏
答:
0赞
VBasic2008
11/21/2022
#1
计算索引/匹配数组公式
Sub EvaluateIndexMatchFormula()
' Write the formula to a string first...
Dim Formula As String: Formula _
= "=IFERROR(INDEX('Sheet1'!K:K," _
& "MATCH(1,(L3='Sheet1'!G:G)*(Q3='Sheet1'!J:J),0)),"""")"
' ... so you can test it with:
'Debug.Print Formula
Dim wb As Workbook: Set wb = ThisWorkbook ' workbook containing this code
Dim dws As Worksheet: Set dws = wb.Worksheets("Sheet2") ' adjust!
Dim drg As Range ' Destination Range
With dws.UsedRange
Set drg = dws.Range("P3", dws.Cells(.Rows.Count + .Row - 1, "P"))
End With
With drg
' Write formulae.
With .Cells(1)
.FormulaArray = Formula
.AutoFill drg, xlFillDefault
End With
' Keep only values.
.Value = .Value
End With
End Sub
上一个:在匹配多个条件的范围内搜索行
评论
Range("P3:P100").Formula = "index('Sheet1'!$K:$K,MATCH(1,(L3='Sheet1'!$G:$G)*(Q3='Sheet1'!$J:$J),0))"
, .Range("P3:P100").Value = Range("P3:P100").Value