Thread: Formula Macro
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Michael M Michael M is offline
external usenet poster
 
Posts: 118
Default Formula Macro

Gents again
I have tried both examples of the code and both give me a "runtime error 1004"

Jim, I understand what the macro is doing, as I am importing data into a new
sheet then inserting formulae over what was previously, value only data.
But it's good to know it makes sense !!

Regards
Michael M

"Jim Thomlinson" wrote:

For a quick translation here is what that macro is doing... It is finding the
last populated cell in column F by going to Cell F65536 and then moving up
from there. It then goes to Cell F14 and puts a formula in there... it copies
that formula and pastes it into Cells F15 to the last populated Cell in F...
That seems odd to me unless you are just rying to overwrtie existing data in
F the last cell found will probably be something like F13... Give this a
try... It uses column D to determine the last row.

Sub CopyFormula()
Dim FinalRow As Long
FinalRow = cells(rows.count, "D").End(xlUp).Row 'Use D to determine last row
Range("F14").Formula = "=IF(OR(D14="",D14=0),"",G14/D14)"
Range("F14").Copy Destination:=Range("F15:F" & FinalRow)
End Sub

--
HTH...

Jim Thomlinson


"Michael M" wrote:

Hi all
I really don't seem to be able to come to grips with VBA
I have copied this formula verbatim from a VBA text book and it doesn't work
for me.
Can someone please give me some guidance as to where I am going wrong.


Sub CopyFormula()
Dim FinalRow As Long
FinalRow = Range("F65536").End(xlUp).Row
Range("F14").Formula = "=IF(OR(D14="",D14=0),"",G14/D14)"
Range("F14").Copy Destination:=Range("F15:F" & FinalRow)
End Sub

Regards to all that may help
Michael M