[英]Excel VBA with Index Match
一直在嘗試解決以下問題,但到目前為止還沒有成功,尋求您的幫助:
vba公式返回多了兩個“@”,如何修復代碼或刪除單元格R1中的“@”?
如果我想做一個循環並從單元格 R1 到 R30 運行 vba 代碼,我應該修改代碼的哪一部分?
Dim PartPoError As Range Dim PART As Range Dim PO As Range Dim lastrow As Long lastrow1 = Sheets("TEMPLATE").Cells(Rows.Count, "A").End(xlUp).Row x = "J" & lastrow1 t = "A" & lastrow1 V = "B" & lastrow1 Set PartPoError = Sheets("rpt_sense").Range("A1", x) Set PART = Sheets("rpt_sense").Range("A1", t) Set PO = Sheets("rpt_sense").Range("B1", V) With Worksheets("rpt_sense").Range(.Cells(2, 23), .Cells(lastrow1, 23)).ClearContents.Range(.Cells(2, 23), .Cells(lastrow1, 23)).Formula = "=A2&B2" End With lastrow2 = Sheets("template").Cells(Rows.Count, "A").End(xlUp).Row For s = lastrow2 To 16 Step -1 If Sheets("template").Cells(s, 10).Value = "" Then ' Stuck in below formula error....it retunred with extra two "@" in cell formula R1..... Sheets("template").Cells(s, 10) = "=INDEX('rpt_sense':r,r" & ",MATCH('template':c8" & "&'template':B" & s & ",'rpt_sense',a:a" & "&'rpt_sense'!f:f" & ",0),1)" End If Next s
對不起,我不完全明白你想做什么..你能分享你的最終 output 的截圖嗎..
Dim PartPoError As Range
Dim PART As Range
Dim PO As Range
Dim lastrow As Long
lastrow1 = Sheets("TEMPLATE").Cells(Rows.Count, "A").End(xlUp).Row
'I think this variant variable is not required if you just want to use range.
x = "J" & lastrow1
t = "A" & lastrow1
V = "B" & lastrow1
'The change will be like this.
Set PartPoError = Sheets("rpt_sense").Range("A1","J" & lastrow1)
Set PART = Sheets("rpt_sense").Range("A1", "A" & lastrow1)
Set PO = Sheets("rpt_sense").Range("B1","B" & lastrow1)
With Worksheets("rpt_sense")
.Range(.Cells(2, 23), .Cells(lastrow1, 23)).ClearContents
.Range(.Cells(2, 23), .Cells(lastrow1, 23)).Formula = "=A2&B2"
End With
lastrow2 = Sheets("template").Cells(Rows.Count, "A").End(xlUp).Row
For s = lastrow2 To 16 Step -1
If Sheets("template").Cells(s, 10).Value = "" Then
'Please clear what actually you want to do here..
' Stuck in below formula error....it retunred with extra two "@" in cell formula R1.....
Sheets("template").Cells(s, 10) = "=INDEX('rpt_sense'!r:r" & ",MATCH('template'!c8" & "&'template'!B" & s & ",'rpt_sense'!a:a" & "&'rpt_sense'!f:f" & ",0),1)"
End If
Next s
如果您想按 ID 和日期查找銷售額和收入,我認為您不需要 vba 代碼:
以下是根據兩個標准查找銷售額的公式:
=INDEX(Sheet2:C2,C3,MATCH(1:INDEX((Sheet3:ID(cell)=Sheet2,A2,A3)*(Sheet3,date(cell)=Sheet2!B2:B3),0,1), 0))
此處 1.Sheet2 = 您的數據存儲位置。 2.sheet3 = 您要查找銷售額和收入的位置 3.使用 ID 作為絕對參考 3.使用日期作為相對參考。 讓我知道它是否有效。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.