VBA: Selecting range by variables

前端 未结 6 910
甜味超标
甜味超标 2020-12-02 21:28

I want to select the formatted range of an Excel sheet. To define the last and first row I use the following functions:

lastColumn = ActiveSheet.UsedRange.Co         


        
6条回答
  •  悲哀的现实
    2020-12-02 22:01

    I tried using:

    Range(cells(1, 1), cells(lastRow, lastColumn)).Select 
    

    where lastRow and lastColumn are integers, but received run-time error 1004. I'm using an older VB (6.5).

    What did work was to use the following:

    Range(Chr(64 + firstColumn) & firstRow & ":" & Chr(64 + lastColumn) & firstColumn).Select.  
    

提交回复
热议问题