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

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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,
 
A function cannot trigger a macro

--

HTH

RP
(remove nothere from the email address if mailing direct)
 
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)
 
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.
 
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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top