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

前端 未结 11 758
萌比男神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:24

    Sub SelectAllCellsInSheet(SheetName As String)
        lastCol = Sheets(SheetName).Range("a1").End(xlToRight).Column
        Lastrow = Sheets(SheetName).Cells(1, 1).End(xlDown).Row
        Sheets(SheetName).Range("A1", Sheets(SheetName).Cells(Lastrow, lastCol)).Select
    End Sub
    

    To use with ActiveSheet:

    Call SelectAllCellsInSheet(ActiveSheet.Name)
    

提交回复
热议问题