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

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
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,218,204
Messages
6,141,095
Members
450,336
Latest member
bschermerhorn

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