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

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

GlennUK

Well-known Member
Joined
Jul 8, 2002
Messages
11,701
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:
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,168,117
Messages
5,857,482
Members
431,882
Latest member
saaaaaaaaaaaaaaaaaaaaaa

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