View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Gary Keramidas[_2_] Gary Keramidas[_2_] is offline
external usenet poster
 
Posts: 364
Default macro doesn't work

a couple things. your code, if it worked, would fill column N to row 65536 in
excel 2007. I don't think this is what you want.
change the sheet name in my code to match yours.
watch out for wordwrap, the underscores show where the line breaks
change the range to filldown
you'll have to determine if the formula is correct.

Sub test()
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")
With ws.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)"
End With
ws.Range("N15:N25").FillDown
End Sub


--


Gary K



"Seeker" wrote in message
...
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