0

I would like to set a range in which the row range is from 2 - "column D end" and the column range is from 4 (or D) to "4 + iCount". Example: If iCount = 4 & the last value in column D is in row 22, then I would like the range to be Range(D2:H22) / Range(Cells(2, 4), Cells(22, 8)).

This is the macro I wrote:

Range(Cells(2, 4), Cells((Range("D1").End(xlDown)), 4 + iCount)).Interior.Color = vbBlue

The column range works, but it only selects the second row and does not go down to the row with the last value in column D.

Thanks guys!

disskyze
  • 45
  • 5
  • 1
    `Dim lastRow As Long`, `lastRow = Cells(Rows.Count, "D").End(xlUp).Row`, then replace `(Range("D1").End(xlDown))` with `lastRow`. – BigBen May 25 '22 at 15:33
  • Thank you, this looks better. However, because the values are all in a table, it sets the last row as the bottom of the table, not where the last value in column D within the table is... – disskyze May 25 '22 at 15:46
  • 1
    Then see the section *Find Last Row in a Table (ListObject)* in the linked thread, and use that approach to find the last row. – BigBen May 25 '22 at 15:47

0 Answers0