Search code examples
excelvbarow

Select from Row 1 to 27 in last used column


I have this code to select cell 1 from the last used column.

.Cells(1, .Columns.Count).End(xlToLeft).Select

Now I want to select this cell 1 and 27 cells down to make a border.

How can i select those cells?


Solution

  • Don't select that cell, but rather Set a Range() object variable, then Resize() that object and add borders, for example:

    Set cl = .Cells(1, .Columns.Count).End(xlToLeft)
    cl.Resize(27).BorderAround ColorIndex:=3, Weight:=xlThick