Guys if I use the following code:
dim Defaultcol As Long
Defaultcol = Sheets("Whatever").Cells(1, 1).Interior.Color
I can get the color formatting from a cell.
Could I also write something like
dim FullFormat as object (Or dim FullFormat as cellformat)
set FullFormat = Sheets("Whatever").Cells(1, 1).formats
and get all the formats of a cell in one object?
or maybe
dim sourcecell as cell
set sourcecell = Sheets("Whatever").Cells(1, 1)
and then have property sourcecell.formats
that I could use?
Thanks in advance.
There is a way to copy the basic formatting of a cell using MSND's Guide
While the above may be a workaround when it comes to VBA there is no direct way of copying cells Styles/Formatting.
It's true that the
Style
object stores the styles but no methods exist (at least I am not aware of any) which allow you to use theStyle
object to copy and apply formatting between cells.There is a workaround it using VBA
One way is to use
String
arguments to copyfrom
andto
ie.and Call it like
and this will copy the formatting and retain the Value unlike lots of online guides which only copy and paste the cell
A better way would be to pass reference to
Range
objects as it allwos you to use it in between different sheets etc.Example