VBA copy formatting from one sheet and paste in another sheet

Cooki

Board Regular
Joined
Jul 31, 2018
Messages
86
I need some VBA to do the formatting auto

5 Sheets
1st sheet formatting template
other 4 Q1 / Q2 / Q3 / Q4

Button needs to be on each of the Q's, need to copy formatting from formatting template and paste it from A2 down to last row with data

Formatting on formatting template
Q1 is from B2 to AS2
Q2 is from B3 to AS3
Q3 is from B4 to AS4
Q4 is from B5 to AS5

your help would be very much appriciated
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Encase anyone comes across this and wants to know ive figured it out

Sub Formatting()

' Turn off screen updating
Application.ScreenUpdating = False

' Define the main sheet
Dim mainSheet As Worksheet
Set mainSheet = ThisWorkbook.Worksheets("Q1")

' Define the sheet containing the formatting
Dim formatSheet As Worksheet
Set formatSheet = ThisWorkbook.Worksheets("Formatting")

' Define the first row on the main sheet containing data
Dim firstDataRow As Integer
firstDataRow = 2

' Placeholder for row reference, start at the first data row
Dim rowRef As Integer
rowRef = firstDataRow

' Reset the row reference
rowRef = firstDataRow

' Copy the formatting required from the format sheet
formatSheet.Range("$B$2:$AS$2").Copy

' Paste the formatting to the first line with data
mainSheet.Range("A" & rowRef).PasteSpecial Paste:=xlPasteFormats

' Following that, copy the formatting from the first data row, down.
mainSheet.Range("A" & rowRef & ":AR" & rowRef).Copy
' Move to next row
rowRef = rowRef + 1

' Paste formatting to remainder of the data
Do While mainSheet.Cells(rowRef, 1) <> ""
mainSheet.Range("A" & rowRef).PasteSpecial Paste:=xlPasteFormats
rowRef = rowRef + 1
Loop

' Turn on screen updating
Application.ScreenUpdating = True

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,195
Members
452,616
Latest member
intern444

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