VBA - Copy entire border style from one cell to another

gamex

New Member
Joined
Jul 20, 2005
Messages
5
I have a pivot table that displays some data, and I need to create a macro that creates some cells next to the pivot table. I would like to be able to loop through a column in the pivot table, and copy the entire border style of each cell to another column. I was hoping it would be as simple as this:

ActiveCell.Offset(0, 5).Borders = ActiveCell.Borders

But I guess that would have been wishful thinking.

Is there an easy way to just copy the entire cell's style (border, background color, font style (bold, italic, etc)) to a new cell?
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Something like:

Code:
ActiveCell.Offset(0, 5).Borders().linestyle = ActiveCell.Borders().linestyle
 
Upvote 0
you could also try:

Code:
Sub test()
    With ActiveCell
        .Copy
        .Offset(, 5).PasteSpecial Paste:=xlPasteFormats
    End With
End Sub
or, if you know the entire range you need to cover beforehand, a more efficient method:
Code:
Sub test2()
    With Range("A1:A1000") 'substitute your range here
        .Copy
        .Offset(, 5).PasteSpecial Paste:=xlPasteFormats
    End With
End Sub
Note, this will also copy text formatting.

HTH
 
Upvote 0

Forum statistics

Threads
1,223,248
Messages
6,171,027
Members
452,374
Latest member
keccles

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