Macro Help

J

Jeremy

I have recorded a macro to hid row 10. How would I automate this macro to
hide if E2 has yes and unhide if it has no?


Thank you

Jeremy
 
J

Jacob Skaria

Sub Mac()
Rows(10).Hidden = IIf(Range("E2") = "Yes", True, False)
End Sub

If this post helps click Yes
 
J

Jeremy

I have it working but you have to play the macro. How would you get the
macro to auto play?
 
D

Don Guillett

Right click sheet tab>view code>insert this
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address <> Range("e2").Address Then Exit Sub
If LCase(Target) = "yes" Then
Rows(10).Hidden = True
Else
Rows(10).Hidden = False
End If
End Sub
 
J

Jacob Skaria

Right click the sheet tab>View code and paste the below code and try

Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
If Not Application.Intersect(Target, Range("E2")) Is Nothing Then
Rows(10).Hidden = IIf(Range("E2") = "Yes", True, False)
End If
Application.EnableEvents = True
End Sub

If this post helps click Yes
 
D

Don Guillett

I had forgotten about I if. Minor tweaks
Private Sub Worksheet_Change(ByVal Target As Range)
'Application.EnableEvents = False' not necessary
If Not Application.Intersect(Target, Range("E2")) Is Nothing Then
Rows(10).Hidden = IIf(UCase(Range("E2")) = "YES", True, False)'spelling
End If
'Application.EnableEvents = True
End Sub
 
J

Jeremy

Do I place this in the macro when I edit it?

Don Guillett said:
I had forgotten about I if. Minor tweaks
Private Sub Worksheet_Change(ByVal Target As Range)
'Application.EnableEvents = False' not necessary
If Not Application.Intersect(Target, Range("E2")) Is Nothing Then
Rows(10).Hidden = IIf(UCase(Range("E2")) = "YES", True, False)'spelling
End If
'Application.EnableEvents = True
End Sub
--
Don Guillett
Microsoft MVP Excel
SalesAid Software
(e-mail address removed)
 
D

Don Guillett

If you always use Yes you can leave as is. But, if YES or yes or yEs then
change the one line.
Or, use mine instead.
 
J

Jacob Skaria

Dont forget to set the Security level to low/medium in (Tools|Macro|Security)..

If this post helps click Yes
 

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

Similar Threads

Unhide macro worksheet 2
Unhide a workbook? 1
Macro that will unhide then hide rows 10
Macro "on off" switch 3
Automate Macro 3
Insert New Row 1
Data Validation List Macro 18
Recorded macro 4

Top