Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default run macro when drop down box equals

I have the following macro that I want to run when cell M9 equals either
"AR1" or "AR2". Is this possible? thanks!

Sub Macro7()
If Range("M9").Value = "AR1" Then
Rows("60:89").Select
Selection.EntireRow.Hidden = False
Rows("90:112").Select
Selection.EntireRow.Hidden = True
Else
Rows("90:112").Select
Selection.EntireRow.Hidden = False
Rows("60:89").Select
Selection.EntireRow.Hidden = True
End If
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,355
Default run macro when drop down box equals

You're close. Right click on the worksheet tab where the data is being
changed and select View Code. Paste this in

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim myRange As Range

If Target.Count 1 Then Exit Sub

Set myRange = Me.Range("M9")

If Intersect(Target, myRange) Is Nothing Then Exit Sub

If myRange.Value = "AR1" Then
On Error Resume Next
Me.Rows("60:89").EntireRow.Hidden = False
Me.Rows("90:112").EntireRow.Hidden = True
On Error GoTo 0
Else
On Error Resume Next
Me.Rows("90:112").EntireRow.Hidden = False
Me.Rows("60:89").EntireRow.Hidden = True
On Error GoTo 0

End If

End Sub


I added the On error statements becuase IIRC, when the cells are already
hidden and you try to hide them, you get an error.

--
HTH,
Barb Reinhardt

If this post was helpful to you, please click YES below.



"jpzachar" wrote:

I have the following macro that I want to run when cell M9 equals either
"AR1" or "AR2". Is this possible? thanks!

Sub Macro7()
If Range("M9").Value = "AR1" Then
Rows("60:89").Select
Selection.EntireRow.Hidden = False
Rows("90:112").Select
Selection.EntireRow.Hidden = True
Else
Rows("90:112").Select
Selection.EntireRow.Hidden = False
Rows("60:89").Select
Selection.EntireRow.Hidden = True
End If
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default run macro when drop down box equals

Thank you!!!! so much

"Barb Reinhardt" wrote:

You're close. Right click on the worksheet tab where the data is being
changed and select View Code. Paste this in

Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim myRange As Range

If Target.Count 1 Then Exit Sub

Set myRange = Me.Range("M9")

If Intersect(Target, myRange) Is Nothing Then Exit Sub

If myRange.Value = "AR1" Then
On Error Resume Next
Me.Rows("60:89").EntireRow.Hidden = False
Me.Rows("90:112").EntireRow.Hidden = True
On Error GoTo 0
Else
On Error Resume Next
Me.Rows("90:112").EntireRow.Hidden = False
Me.Rows("60:89").EntireRow.Hidden = True
On Error GoTo 0

End If

End Sub


I added the On error statements becuase IIRC, when the cells are already
hidden and you try to hide them, you get an error.

--
HTH,
Barb Reinhardt

If this post was helpful to you, please click YES below.



"jpzachar" wrote:

I have the following macro that I want to run when cell M9 equals either
"AR1" or "AR2". Is this possible? thanks!

Sub Macro7()
If Range("M9").Value = "AR1" Then
Rows("60:89").Select
Selection.EntireRow.Hidden = False
Rows("90:112").Select
Selection.EntireRow.Hidden = True
Else
Rows("90:112").Select
Selection.EntireRow.Hidden = False
Rows("60:89").Select
Selection.EntireRow.Hidden = True
End If
End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
If a cell equals then macro transferxxx Excel Programming 6 November 7th 07 02:49 AM
If a cell equals _, at the next row that equals _, return value fr CathyH Excel Worksheet Functions 10 May 2nd 07 07:53 PM
if a:a (range) equals january and c:c equals gas then add g:g ($) BCOz Excel Worksheet Functions 4 December 29th 05 07:40 PM
how to run a macro when a calculation equals a certin number Kevin Jones Excel Worksheet Functions 0 October 25th 05 09:23 PM
custom filter does not work when selecting 'equals' X AND 'equals' plindman Excel Discussion (Misc queries) 1 June 1st 05 11:29 PM


All times are GMT +1. The time now is 04:45 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"