簡體   English   中英

使用 VBA,我想計算行數,然后在特定單元格中打印

[英]Using VBA, I want to count the number of rows and then print this in a specific cell

這是我正在使用的代碼,但它不起作用

Sub CountRowsAndPrintInColumnQ()
    
        Dim last_row As Long
        Dim Result As Long
        Set last_row = Cells(Rows.Count, 1).End(xlUp).Row
        Set Result = Range("Q1")
        
        Result.Value = last_row
        
    End Sub

本質上,我希望它計算行數,然后在 Q1 中打印值。

提前致謝。

嘗試這個:

Sub CountRowsAndPrintInColumnQ()
    Dim Index As Long

    Index = 1
    Do Until Range("A" & Index).Value = ""
        Index = Index + 1
    Loop
    Range("Q1").Value = Index
End Sub

也是一種選擇

Sub CountRowsAndPrintInColumnQ()
         'This will write  column "A"  number of rows into cell Q1
        ActiveSheet.Range("Q1").Value = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row
 End Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM