VBA: Selecting range by variables

前端 未结 6 901
甜味超标
甜味超标 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条回答
  •  萌比男神i
    2020-12-02 22:00

    I ran into something similar - I wanted to create a range based on some variables. Using the Worksheet.Cells did not work directly since I think the cell's values were passed to Range.

    This did work though:

    Range(Cells(1, 1).Address(), Cells(lastRow, lastColumn).Address()).Select
    

    That took care of converting the cell's numerical location to what Range expects, which is the A1 format.

提交回复
热议问题