Search code examples
vbaexceldynamic-values

Defining dynamic ranges in vba


How do I specify the cell in the column next to the very last cell with data in a spreadsheet e.g. if I have data in

Range(Cells(1, 1), Cells(lastRow, lastColumn))

How do I dynamically define

Range(Cells(1, 2), Cells(lastRow, n_lastColumn))

In a function such that n_lastColumn refers to the next column after lastColumn?


Solution

  • Range(Cells(1,1), Cells(lastRow, lastColumn)).offset(,1)

    or

    Range("A1").currentregion.offset(,1)