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

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

    Here is what I used, I know it could use some perfecting, but I think it will help others...

    ''STYLING''
    
    Dim sheet As Range
    
    ' Find Number of rows used
    Dim Final As Variant
        Final = Range("A1").End(xlDown).Row
    
    ' Find Last Column
    Dim lCol As Long
        lCol = Cells(1, Columns.Count).End(xlToLeft).Column
    
    Set sheet = ActiveWorkbook.ActiveSheet.Range("A" & Final & "", Cells(1, lCol ))
    With sheet
        .Interior.ColorIndex = 1
    End With
    

提交回复
热议问题