[英]VBA Excel File not compiling: Sub or Function not defined
這是相關的代碼:它說錯誤是在函數operation()的定義中,我感覺我需要包括一些東西,但是我不確定是什么。 有人可以建議我需要做什么嗎? 我知道要轉到“工具”>“引用”>“ ..”,但是此后我不確定。
Sub operation()
'
' Macro5 Macro
'
'
Dim Erw, firstRow, lastRow
firstRow = 1
Last Row = Range("B" & Rows.Count).End(xlUp).Row
For Erw = firstRow To lastRow
Dim newRow
newRow = firstRow + 4
Range("B" & newRow).Select
ActiveCell.FormulaR1C1 = Range("B" & newRow)
With ActiveSheet.QueryTables.Add(Connection:= _
"URL;ActiveCell.FormulaR1C1", _
Destination:=Range("$D$5"))
.Name = "collections1504_1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
nextRow = nextRow + 1
Next Erw
Range("D3").Select
Selection.Copy
Range("C5").Select
Selection.PasteSpecial Paste:=xlPasteValues, operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("D5:P143").Select
Application.CutCopyMode = False
Selection.QueryTable.Delete
Selection.ClearContents
End Sub
您的變量名中有一個錯字。 你有:
Last Row = Range("B" & Rows.Count).End(xlUp).Row
但應該是:
lastRow = Range("B" & Rows.Count).End(xlUp).Row
如果你把
Option Explicit
在模塊頂部,您會得到一條稍微有用的錯誤消息。 您確實應該養成包括它的習慣,因為它將檢查以確保所有變量都已聲明。 實際上,它非常有用,您可以在默認情況下在模塊創建時對其進行設置。 在VBA IDE中,轉到“工具=>選項=>”,然后選中標記為“需要變量聲明”的框。
正如編譯器告訴您的(並暫停運行),未定義函數Last
:空間太多:
Last Row
應該
lastRow
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.