遇到以下代码问题。它说我运行它时编译错误,但我认为我遇到了更大的问题。我想要完成的任务:
非常感谢您的帮助
Dim curDate As String, Fname As String
curDate = Format(Date, "yyyy-mm-dd")
Dim wba As Workbook
Fname = "Y:\Consumables\Company\ABC\ABC - Planning & Materials\On Hand Reports\ABC Site\" & curDate & "_INV_R12_ABC_Onhandreport.xlsx"
Set wba = Workbooks.Open(Filename:=Fname, UpdateLinks:=False, Notify:=False)
Dim wb As Workbook
For Each wb In Application.Workbooks
If wb.Name Like "*Master KB-PFEP" Then wb.Activate
wb.Worksheets("Master").AutoFilter.Sort.SortFields.Clear
If (Worksheets("Master Data").AutoFilterMode And Worksheets("Master Data").FilterMode) Or Worksheets("Master Data").FilterMode Then
Worksheets("Master Data").ShowAllData
End If
Range("AL8:A" & Cells(Rows.Count, "A").End(xlUp).Row).Formula = "=SUMIF('Inv Report'!C[-36],RC[-36],'Inv Report'!C[-21])"
End If
End Sub
答案 0 :(得分:1)
当条件代码位于同一行时,您不需要End If
:
If wb.Name Like "*Master KB-PFEP" Then wb.Activate
这意味着你底部有一个额外的。解决之后,您需要在Next
之前的某处添加缺少的End Sub
。
答案 1 :(得分:0)
我想你应该拥有的是什么(没有检查你的R1C1值):
wb.Activate
FormulaR1C1
代替Formula
Next
End Sub
醇>
Sub SO_30042563()
Dim curDate As String, Fname As String
curDate = Format(Date, "yyyy-mm-dd")
Dim wba As Workbook, wb As Workbook
Fname = "Y:\Consumables\Company\ABC\ABC - Planning & Materials\On Hand Reports\ABC Site\" & curDate & "_INV_R12_ABC_Onhandreport.xlsx"
Set wba = Workbooks.Open(Filename:=Fname, UpdateLinks:=False, Notify:=False)
For Each wb In Application.Workbooks
If wb.Name Like "*Master KB-PFEP" Then
wb.Activate
wb.Worksheets("Master").AutoFilter.Sort.SortFields.Clear
If (Worksheets("Master Data").AutoFilterMode And Worksheets("Master Data").FilterMode) Or Worksheets("Master Data").FilterMode Then
Worksheets("Master Data").ShowAllData
End If
Range("AL8:A" & Cells(Rows.Count, "A").End(xlUp).Row).FormulaR1C1 = "=SUMIF('Inv Report'!C[-36],RC[-36],'Inv Report'!C[-21])"
End If
Next
End Sub