Help With Formatting A Spreadsheet Using VBA

TkdKidSnake

Active Member
Joined
Nov 27, 2012
Messages
255
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I have a spreadsheet that I would like to use VBA to automatically format / copy and paste certain things. The spreadsheet varies in length and currently I need to do this manually which is quite time consuming.

If anyone can help it would be greatly appreciated.


  1. Copy the formats on row 6 then pastes the formats only all the way to the bottom to the last populated row using column B as this will always have something in


  1. Column K6, L6, Q6 & U6 all have formula that I’d like to copy all the way to the bottom using the same criteria as in item1

Just in case you need to know I have called the workbook “002 – Raw Data.xls”


Thanks in advance.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Try this:
Code:
Sub Formats()

Dim lrow As Long
lrow = Cells(Rows.Count, 2).End(xlUp).Row
Range("6:6").Copy
Range("6:" & lrow).PasteSpecial Paste:=xlPasteFormats
Range("K6:L6").Copy
Range("K6:L" & lrow).PasteSpecial Paste:=xlPasteFormulas
Range("Q6").Copy
Range("Q6:Q" & lrow).PasteSpecial Paste:=xlPasteFormulas
Range("U6").Copy
Range("U6:U" & lrow).PasteSpecial Paste:=xlPasteFormulas

End Sub
 
Upvote 0
How about
Code:
Sub CopyFormat()

   Dim UsdRws As Long
   UsdRws = Range("B" & Rows.Count).End(xlUp).Row
   
   Intersect(Range("K6:U" & UsdRws), Range("K:L,Q:Q,U:U")).FillDown
   Range("A6:U6").Copy
   Range("A7:[COLOR=#ff0000]U[/COLOR]" & UsdRws).PasteSpecial xlPasteFormats
   Application.CutCopyMode = False
End Sub
Change the value in red to match your final column
 
Upvote 0
Excellent thanks works a treat

Try this:
Code:
Sub Formats()

Dim lrow As Long
lrow = Cells(Rows.Count, 2).End(xlUp).Row
Range("6:6").Copy
Range("6:" & lrow).PasteSpecial Paste:=xlPasteFormats
Range("K6:L6").Copy
Range("K6:L" & lrow).PasteSpecial Paste:=xlPasteFormulas
Range("Q6").Copy
Range("Q6:Q" & lrow).PasteSpecial Paste:=xlPasteFormulas
Range("U6").Copy
Range("U6:U" & lrow).PasteSpecial Paste:=xlPasteFormulas

End Sub
 
Upvote 0
Excellent thanks both options work a treat

How about
Code:
Sub CopyFormat()

   Dim UsdRws As Long
   UsdRws = Range("B" & Rows.Count).End(xlUp).Row
   
   Intersect(Range("K6:U" & UsdRws), Range("K:L,Q:Q,U:U")).FillDown
   Range("A6:U6").Copy
   Range("A7:[COLOR=#ff0000]U[/COLOR]" & UsdRws).PasteSpecial xlPasteFormats
   Application.CutCopyMode = False
End Sub
Change the value in red to match your final column
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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