[英]VBA WorksheetFunction
我在我的 VBA 中有這些條目,而不是使用 WorksheetFunction,因為我無法弄清楚如何讓它工作......
如果可能的話,我希望至少將前兩行替換為 WorksheetFunction。 任何幫助將不勝感激。 提前致謝!
Application.Goto Reference:="'Handling Units'!HUNUM01"
ActiveCell.FormulaR1C1 = "=IFERROR((WHNUMB&REPT(0,14-LEN(STARTNUMB))&STARTNUMB+(RC[-1]-1)),"""")"
Selection.AutoFill Destination:=Range("B5:B" & Range("A" & Rows.Count).End(xlUp).Row)
我最終只是這樣做了,看起來比以前更簡單,更有效。
Range("'Handling Units'!HUNUM01").FormulaR1C1 = "=IFERROR((WHNUMB&REPT(0,14-LEN(STARTNUMB))&STARTNUMB+(RC[-1]-1)),"""")"
Range("'Handling Units'!HUNUM01").AutoFill Destination:= Range("B5:B" & Range("A" & Rows.Count).End(xlUp).Row)
確保工作表中的每個對象(如Range
、 Cells
、 Rows
、 Columns
等)都被引用到工作表中!
因此,使用Worksheets("Handling Units").Range("HUNUM01")
比使用Range("'Handling Units'!HUNUM01")
更直接。 在您的代碼中, Destination:= Range("B5:B" & Range("A" & Rows.Count).End(xlUp).Row)
中的范圍沒有指定工作表,因此如果Handling Units
不是活動表。 為避免這種情況,請為位於工作表中的所有對象指定一個工作表。 不要讓 Excel 猜測,它可能會猜錯!
With ThisWorkbook.Worksheets("Handling Units")
.Range("HUNUM01").FormulaR1C1 = "=IFERROR((WHNUMB&REPT(0,14-LEN(STARTNUMB))&STARTNUMB+(RC[-1]-1)),"""")"
.Range("HUNUM01").AutoFill Destination:= .Range("B5:B" & .Range("A" & .Rows.Count).End(xlUp).Row)
End With
請注意, .Range
中的前導點使用With
語句的工作表生成此Range
。 確保它在那里,否則即使它在With
塊內,它也不會使用With
語句。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.