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.
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

GlennUK

Well-known Member
Joined
Jul 8, 2002
Messages
11,722
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:
 

Forum statistics

Threads
1,171,213
Messages
5,874,391
Members
433,049
Latest member
piyushbund77

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top