Get all cell properties

Ramachandran

New Member
Joined
Oct 17, 2011
Messages
47
I have a table that I sort in a specific matter then "paste" it sorted just below the unsorted one.

Code:
...
for i = 1 to lastRow[INDENT]for j = 1 to 10
[/INDENT]
[INDENT=2]Set oldCell = Cells(sortedArr(i), j)
[/INDENT]
                Cells(i + lastRow, j) = oldCell[INDENT]next j[/INDENT]
next i

This works fine, but only transfers the .value from the old cell.
Say if I wanted to get some additional property, like the font size, I could do:

Code:
Cells(i + lastRow, j).font.size = oldCell.font.size

I would like the new cell to have all properties of the old cell, like it's color, borders, formatting, et cetera.
Is there some magic word, like say cell.EntireContent, that I can use?
 
Code:
oldcell.copy
newcell.pastespecial paste:=xlpasteformats
 
Upvote 0
Thanks, that did the job just fine!
However it was a bit ineffective.

I ended up making a custom copy routine where I added all the properties I needed. That took nearly half the time.

Code:
Private Sub cellProps(newCell As Range, oldCell As Range)
[INDENT]newCell.Value = oldCell.Value
newCell.NumberFormat = oldCell.NumberFormat
newCell.Interior.Color = oldCell.Interior.Color
newCell.HorizontalAlignment = oldCell.HorizontalAlignment
newCell.VerticalAlignment = oldCell.VerticalAlignment
newCell.Borders.Weight = oldCell.Borders.Weight
newCell.Borders.LineStyle = oldCell.Borders.LineStyle
newCell.Font.Name = oldCell.Font.Name
newCell.Font.Color = oldCell.Font.Color
newCell.Font.Size = oldCell.Font.Size
newCell.Font.Bold = oldCell.Font.Bold
[/INDENT]
 End Sub

Code:
...
for i = 1 to lastRow
[INDENT]for j = 1 to 10
[/INDENT]
[INDENT=2]call cellProps(Cells(i + lastRow, j), Cells(sortedArr(i), j))     
[/INDENT]
[INDENT] next j
[/INDENT]
 next i
 
Upvote 0

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