View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default macro doesn't work

You need to use another column instead of N to find the last row of your
data. It the code below I used column A

LastRow = Range("A16").End(xlDown).Row
Range("N15").Formula = _
"=(C15-VLOOKUP(LEFT(A15,3),$A$2:$J$12,5)" & _
"-VLOOKUP(LEFT(A15,3),$A$2:$J$12,6))/" & _
"VLOOKUP(A15,$A$242:$F$352,6)*" & _
"VLOOKUP(LEFT(A15,3),$A$2:$J$12,10)+" & _
"VLOOKUP(LEFT(A15,3),$A$2:$J$12,3)"
Range("N15").Copy _
destination:=Range("N16:N" & LastRow)


"Seeker" wrote:

Could anyone can help to tell me what is wrong with the following macro? It
doesn't perform when I execute it. What I want is place the formula in one
cell, then past it to rest of the cells within range. So the output of
calculation changes because of cell "C15" change to "C16" and so on.
Tks

Range("N15").Select
Range("N15").Formula =
"=(C15-VLOOKUP(LEFT(A15,3),$A$2:$J$12,5)-VLOOKUP(LEFT(A15,3),$A$2:$J$12,6))/VLOOKUP(A15,$A$242:$F$352,6)*VLOOKUP(LEFT(A15,3),$ A$2:$J$12,10)+VLOOKUP(LEFT(A15,3),$A$2:$J$12,3)"
Selection.Copy
Range("N16").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.Paste