0

我有以下代码,并且在 For 循环中的所有部分都出现“无法识别光标下的标识符”。

Sub Finalize_Macro()
'
' Finalize all data on the Offer Data worksheet
'


Dim DSheet As Worksheet
Dim PSheet As Worksheet
Dim LastRow As Long
Dim ValCol As Long
Dim DayCol As Long
Dim i As Integer

Set DSheet = Worksheets("Offer Data")
Set PSheet = Worksheets("PivotTable")
LastRow = DSheet.Cells(Rows.Count, 1).End(xlUp).Row
ValCol = PSheet.Cells(2, Columns.Count).End(xlToLeft).Column - 1 
DayCol = PSheet.Cells(2, Columns.Count).End(xlToLeft).Column 


DSheet.Select
[E1:I1] = [{"Redemption Value", "Redemption Days", "Theo", "Actual", "Rated Days"}]

For i = 2 To LastRow
    Cells(i, 5).Formula = "=IFERROR(XLOOKUP(A" & i & ",PivotTable!(A:A),PivotTable!.Columns(" & ValCol & ")),0)"
    Cells(i, 6).Formula = "=IFERROR(XLOOKUP(A" & i & ",PivotTable!(A:A),PivotTable!.Columns(" & DayCol & ")),0)"
    Cells(i, 7).Formula = "=IFERROR(XLOOKUP(A" & i & ",'Big Query Data'!(B:B),'Big Query Data'!(C:C)),0)"
    Cells(i, 8).Formula = "=IFERROR(XLOOKUP(A" & i & ",'Big Query Data'!(B:B),'Big Query Data'!(D:D)),0)"
    Cells(i, 9).Formula = "=IFERROR(XLOOKUP(A" & i & ",'Big Query Data'!(B:B),'Big Query Data'!(E:E)),0)"
Next
                        
                        
   Application.DisplayAlerts = True
   Application.ScreenUpdating = True


End Sub

如果有人可以帮助告知为什么这不起作用,我将不胜感激!

4

1 回答 1

2

这就是我最终使用的 - 感谢 ScottCraner 和 BigBen 的帮助!

    Sub Finalize_Macro()
'
' Finalize all data on the Offer Data worksheet
'


Dim DSheet As Worksheet
Dim PSheet As Worksheet
Dim LastRow As Long
Dim ValCol As Long
Dim DayCol As Long
Dim i As Integer

Set DSheet = Worksheets("Offer Data")
Set PSheet = Worksheets("PivotTable")
LastRow = DSheet.Cells(Rows.Count, 1).End(xlUp).Row
ValCol = PSheet.Cells(2, Columns.Count).End(xlToLeft).Column - 1 
DayCol = PSheet.Cells(2, Columns.Count).End(xlToLeft).Column 


DSheet.Select
[E1:I1] = [{"Redemption Value", "Redemption Days", "Theo", "Actual", "Rated Days"}]

    Range("E2:E" & LastRow).Formula2 = "=IFERROR(XLOOKUP($A2,PivotTable!$A:$A,PivotTable!" & PSheet.Columns(ValCol).Address & "),0)"
    Range("F2:F" & LastRow).Formula2 = "=IFERROR(XLOOKUP($A2,PivotTable!$A:$A,PivotTable!" & PSheet.Columns(ValCol).Address & "),0)"
    Range("G2:G" & LastRow).Formula2 = "=IFERROR(XLOOKUP($A2,'Big Query Data'!$B:$B,'Big Query Data'!$C:$C),0)"
    Range("H2:H" & LastRow).Formula2 = "=IFERROR(XLOOKUP($A2,'Big Query Data'!$B:$B,'Big Query Data'!$D:$D),0)"
    Range("I2:I" & LastRow).Formula2 = "=IFERROR(XLOOKUP($A2,'Big Query Data'!$B:$B,'Big Query Data'!$E:$E),0)"
    
                        
                        
   Application.DisplayAlerts = True
   Application.ScreenUpdating = True


End Sub
于 2021-08-31T18:42:34.010 回答