View Single Post
  #3   Report Post  
Bob Phillips
 
Posts: n/a
Default Is it possible to insert a macro command in an "IF" function?

Sorry, didn't finish

A function cannot trigger a macro that changes the worksheet, such as
inserting a row. What you could do is check if the value changes to Yes, and
use an event procedure to insert the row. For instance, assuming the value
is in A use this code

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit:
Application.EnableEvents = False
If Target.Column = 1 Then
If LCase(Target.Value) = "yes" Then
Target.EntireRow.Insert
End If
End If

ws_exit:
Application.EnableEvents = True
End Sub

'This is worksheet event code, which means that it needs to be
'placed in the appropriate worksheet code module, not a standard
'code module. To do this, right-click on the sheet tab, select
'the View Code option from the menu, and paste the code in.




--

HTH

RP
(remove nothere from the email address if mailing direct)


"SandyLACA" wrote in message
...
We would like to be able to set up an "IF" function where if the answer is
yes a row will be inserted. This would seem to require a macro being
triggered but we don't know how to do that. If there is some other way of
accomplishing that we would appreciate the help.
Thank you,