View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default Insert formula and copy to a range of cells above

This macro will find the asterisk and replace it plus all the cells above it
(up to E2) with the subtraction formula you said you wanted...

Sub ReplaceAsteriskAndFillUpwards()
Range("E2:E" & Columns("E").Find("~*").Row).Formula = "=D2-C2"
End Sub

--
Rick (MVP - Excel)


"mickjjuk" wrote in message
...
Can anyone help.

I have some data being output to an excel worksheet and the number of rows
output is never the same.

I have written some code to find the last row used and then select the
cell
in this row relating to a certain column. I am now having trouble
insetring
a formula into this cell and copying this formula to all the cells above
in
the same column.

a sample worksheet would look like this:

Tag num Jig Num Wgt A Wgt B Wgt Diff
1 100 90 95
2 101 85 95
6 130 110 150 *

The code I currenty have selects the cell * above, I then want to insert a
formula in there which subtracts Wgt A from Wgt B, then copy this formula
upwards in the cells in Wgt Diff Column to the row under the heading row.

Can anyone help?

Thanks