Macro autofill to last column

excelgs

New Member
Joined
Jul 23, 2015
Messages
4
New to Macros.
Trying to autofill format only from E1 to the last column (row1 still).
Tried this but it didn't work:

Selection.AutoFill Destination:=Range("E1: & LastColumn & 1"), Type:=xlFillFormats

I have this above it:

Dim sht As Worksheet
Dim LastColumn As Long
Set sht = ThisWorkbook.Worksheets("Sheet1")
Dim DataRange As Range
LastColumn = Cells(2, Columns.Count).End(xlToLeft).Column

I've copied and pasted from several places at this point so that might all be wrong for what I'm trying to do.
Please help, thanks.
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Hi.
Try:

Code:
Sub FillFormat()
 Dim LastColumn As Long
 LastColumn = Cells(1, Columns.Count).End(xlToLeft).Column
 Range("E1").AutoFill Destination:=Range(Range("E1"), Cells(1, LastColumn)), Type:=xlFillFormats
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,094
Latest member
teemeren

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