ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Copy Formula (https://www.excelbanter.com/excel-programming/386198-copy-formula.html)

Ian B

Copy Formula
 
G'Day Helper

I wish to copy the formula that is in Sheet2 for all colums that contain
formula.

The lenght of the rows has to be the same as the number of rows in sheet1
and delete, if any, old formula that goes beyond the new rows
Thanks


Ian



Tom Ogilvy

Copy Formula
 
Sub copyFormula
dim rng as Range
Dim cell as Range
Dim rng2 as Range, rw as Long
set rng2 = worksheets("Sheet1").UsedRange
rw = rng2(rng2.count).row
set rng = worksheets("Sheet2").cells.SpecialCells(xlFormulas )
for each cell in rng
if cell.row <= rw then
with worksheets("Sheet1")
.range(cell.Address).Formula = cell.formula
end with
end if
Next
End Sub

--
Regards,
Tom Ogilvy

would be one interpretation. Make a copy of your workbook and test it on
the copy since it overwrites existing data/formulas. Then if it doesn't do
what you want, you haven't lost anything.

--
Regards,
Tom Ogilvy


"Ian B" wrote:

G'Day Helper

I wish to copy the formula that is in Sheet2 for all colums that contain
formula.

The lenght of the rows has to be the same as the number of rows in sheet1
and delete, if any, old formula that goes beyond the new rows
Thanks


Ian




All times are GMT +1. The time now is 01:14 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com