Find last column and autofill to the right

Rojo Habe

New Member
Joined
Nov 22, 2005
Messages
5
I need to find the last column in the sheet and then autofill formats to the right. In other words I need to do this:

Columns("N:N").AutoFill Destination:=Columns("N:O"), Type:=xlFillFormats

replacing the letters "N" and "O" with variables.

I can find the last column easily enough with

LastCol = Range("A1").End(xlToRight).Column

but this returns a number, not a letter. Simply replacing "N" and "O" above with LastCol and LastCol + 1 returns "Aplication-defined or object-defined error"

I'm using the LastCol variable elsewhere in my code, so would prefer to keep it as a number. What I need, then, is the correct syntax for specifying two columns by number rather than letter. I've searched the help file to no avail.
 

Some videos you may like

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

GlennUK

Well-known Member
Joined
Jul 8, 2002
Messages
11,402
Use this type of syntax:
Range(Columns(5), Columns(7))
to refer to a range of columns numerically.
 

Rojo Habe

New Member
Joined
Nov 22, 2005
Messages
5
Many thanks

I tried many variations on that theme, but evidently never stumbled onto the most obvious one. :oops:
 

Watch MrExcel Video

Forum statistics

Threads
1,118,821
Messages
5,574,515
Members
412,599
Latest member
Schu94
Top