[英]Method 'Range' of object'_Global' Failed in VBA
我是VBA的新手,我有一個代碼,我想計算從A2到工作表末尾沒有多少空行,但是我一直在收到此錯誤,並且代碼如下:
我無法指出問題所在
謝謝帕吉
不清楚OP實際需要什么(由公式得出的“非空白”單元格或“非空白”單元格,或其他)
所以我只舉一些例子:
Option Explicit
Sub TicketCopy()
With Worksheets("Formulas")
With .Range("A2", .Cells(.Rows.Count, 1).End(xlUp)) '<--| reference column "A" cells from row 2 to last not empty one
' all cells in range with formulas only
With .SpecialCells(xlCellTypeFormulas)
MsgBox "The Rows Count= " & .Count ' cells number
MsgBox "The Rows Count= " & WorksheetFunction.Count(.Cells) ' cells resulting "not blank" (a 'zero' is a "not blank")
MsgBox "The Rows Count= " & WorksheetFunction.CountIf(.Cells, "") ' cells resulting "blank" (a 'zero' is a "not blank")
MsgBox "The Rows Count= " & WorksheetFunction.CountBlank(.Cells) ' cells resulting "blank" (a 'zero' is a "not blank")
End With
'all cells in range
MsgBox "The Rows Count= " & .Count ' cells number
MsgBox "The Rows Count= " & WorksheetFunction.Count(.Cells) 'cells resulting "not blank" (a 'zero' is a "not blank")
MsgBox "The Rows Count= " & WorksheetFunction.CountIf(.Cells, "") 'cells resulting "blank" (a 'zero' is a "not blank")
MsgBox "The Rows Count= " & WorksheetFunction.CountBlank(.Cells) ' cells resulting "blank" (a 'zero' is a "not blank")
End With
End With
End Sub
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.