View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
OssieMac OssieMac is offline
external usenet poster
 
Posts: 2,510
Default macro doesn't work

The code will work. It pastes the formula but whether it is calculating the
correct answer is another matter because can't test without all the data.

Need to establish a couple of things.

The following line relies on there being at least one cell below N16 that is
not blank. If they are all blank then it will copy the formula to the bottom
of the worksheet.

Range(Selection, Selection.End(xlDown)).Select

Also, if the code is in an event then perhaps events are turned off. Events
can get inadvertantly turned off when code is interrupted due to code errors
etc and then they remain off until turned back on by the user or you close
and re-start Excel. (This problem occurs when Application.EnableEvents =
False is used at the start of an event to prevent recursive calls to the sub
but it needs to be turned back on at the end of the sub. However, if code is
interrupted then it never gets turned back on until the user executes some
code to re-enable events.)

To turn events back on use the following sub. It can be run from within the
VBA editor.

Sub ReEnableEvents()
Application.EnableEvents = True
End Sub



--
Regards,

OssieMac


"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