Is it possible to insert a macro command in an "IF" function?

S

SandyLACA

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,
 
B

Bob Phillips

A function cannot trigger a macro

--

HTH

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

Bob Phillips

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)
 
S

SandyLACA

Thank you Bob but this is beyond everyone here. I'll go to the help menu and
look up event procedures and see where it leads me.
 
B

Bob Phillips

Hopefully I gave you all you need. Follow my directions and try it. Post
back then if you have problems.

--

HTH

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