2016-12-02 105 views

回答

1

简单的修复到Set

Sub TicketCopy() 
    With Worksheets("Formulas") 
     Dim K As Range 
     Dim M As Long 
     Set K = Range(.Range("A2"), .Range("A2").End(xlDown)) 
     M = K.Rows.Count 
     MsgBox "The Rows Count=" & M 
    End With 
End Sub 

enter image description here

注意这是比列的底部少一个。

+0

范围不点不参照“公式”工作表 – user3598756

+0

@ user3598756 ** OUCH **!谢谢...........我会修正代码! –

+0

了解,非常感谢! –

0

并不清楚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 
相关问题