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

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Use this type of syntax:
Range(Columns(5), Columns(7))
to refer to a range of columns numerically.
 
Upvote 0
Many thanks

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

Forum statistics

Threads
1,214,832
Messages
6,121,841
Members
449,051
Latest member
excelquestion515

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
Back
Top