Copy format of a cell to a range of other cells in VB

Vol in NC

New Member
Joined
Sep 19, 2016
Messages
1
I am trying to copy the format of one cell, highlight a range of cells and select visible cells only, and paste the format to those cells. The code is below. The last two lines is what is causing it to error. HELP

Selection.Copy
ActiveSheet.Range("$A$1:$LR$513").AutoFilter Field:=5, Criteria1:="PAB"
Range("F7").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hello, can you pls try this? Hope this helps.

Code:
Sub test()
Dim rng As Range
Dim source As Range

'this range below is your source of format you want to have in other cells
' in this case it is "A1"

Set source = [A1]

ActiveSheet.Range("$A$1:$LR$513").AutoFilter Field:=5, Criteria1:="PAB"
Range("F7").Select
Range(Selection, Selection.End(xlToRight).End(xlDown)) _
.SpecialCells(xlCellTypeVisible).Select


Set rng = Selection

rng.NumberFormat = source.NumberFormat


End Sub

regards,

Tom.
 
Upvote 0

Forum statistics

Threads
1,214,605
Messages
6,120,476
Members
448,967
Latest member
visheshkotha

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