View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default How to Copy formats and formulas in vba?

That single line copies the formula, but it puts the same formula in each
cell (all cell references are the same, they don't change in the same way as
when you "copy a formula down")... you need the second line I posted to do
that (it overwrites the "static" formulas with the "copy down" type of
formulas)... I only used the Copy statement to quickly move the format into
the cells where you wanted the formulas.

--
Rick (MVP - Excel)


"DK" wrote in message
...
Hey! I didn't know that one could copy from to in that manner.
Just the one line within the With statment seems to do the entire job.
.Range("ExpRow").Copy .Range(.Cells(1, 1), .Cells(r, c))

Thanks very much Rick.
DK


"Rick Rothstein" wrote in message
...
This will probably work...

r = Range("MtrCounter").Value
c = Range("ExpRow").Columns.Count
With Sheet2
.Range("ExpRow").Copy .Range(.Cells(1, 1), .Cells(r, c))
.Range(.Cells(1, 1), .Cells(r, c)) = Range("ExpRow").Formula
End With

--
Rick (MVP - Excel)


"DK" wrote in message
...
The following statement copies the formulas in one range to another
range of cells.
How can I also copy the formats of "ExpRow"?
Thank you.

...
r = Range("MtrCounter").Value
c = Range("ExpRow").Columns.Count
With Sheet2
.Range(.Cells(1, 1), .Cells(r, c)) = Range("ExpRow").Formula
End With
...