How do you select the entire excel sheet with Range using VBA?

前端 未结 11 596
萌比男神i
萌比男神i 2021-02-01 16:37

I found a similar solution to this question in c# How to Select all the cells in a worksheet in Excel.Range object of c#?

What is the process to do this in VBA?

11条回答
  •  孤独总比滥情好
    2021-02-01 17:00

    I would recommend recording a macro, like found in this post;

    Excel VBA macro to filter records

    But if you are looking to find the end of your data and not the end of the workbook necessary, if there are not empty cells between the beginning and end of your data, I often use something like this;

    R = 1
    Do While Not IsEmpty(Sheets("Sheet1").Cells(R, 1))
        R = R + 1
    Loop
    Range("A5:A" & R).Select 'This will give you a specific selection
    

    You are left with R = to the number of the row after your data ends. This could be used for the column as well, and then you could use something like Cells(C , R).Select, if you made C the column representation.

提交回复
热议问题