Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
daidipya
 
Posts: n/a
Default Want to run two macros without errors

This is the code at present

Sub HideRows1()
Dim Rng As Range
Set Rng = Sheets("input-assumptions").Range("E88")
If Rng.Value = "Yes" Then
Rows("89:89").EntireRow.Hidden = False
Range("E89").Select
ElseIf Rng.Value = "No" Then
Rows("89:122").EntireRow.Hidden = True
Range("E88").Select
End If
End Sub

Sub HideRows2()
Dim Rng As Range
Set Rng = Sheets("input-assumptions").Range("E89")
If Rng.Value = "Yes" Then
Rows("90:122").EntireRow.Hidden = False
Range("E89").Select
ElseIf Rng.Value = "No" Then
Rows("90:121").EntireRow.Hidden = True
Range("E89").Select
End If
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row < 88 Then Exit Sub
If Target.Column < 5 Then Exit Sub
HideRows1
If Target.Row < 89 Then Exit Sub
If Target.Column < 5 Then Exit Sub
HideRows2
End Sub

however to run the HideRows2 macro i need to run the macro from the
tools macro - tab of the excel, while the HideRows1 macro runs on
automatically on slection of Yes or No

Please help me

  #2   Report Post  
Posted to microsoft.public.excel.misc
 
Posts: n/a
Default Want to run two macros without errors

Please change the code to the following

Sub HideRows1()
Dim Rng As Range
Set Rng = Sheets("input-assumptions").Range("E88")
If Rng.Value = "Yes" Then
Rows("89:89").EntireRow.Hidden = False
Range("E89").Select
ElseIf Rng.Value = "No" Then
Rows("89:122").EntireRow.Hidden = True
Range("E88").Select
End If
End Sub

Sub HideRows2()
Dim Rng As Range
Set Rng = Sheets("input-assumptions").Range("E89")
If Rng.Value = "Yes" Then
Rows("90:122").EntireRow.Hidden = False
Range("E89").Select
ElseIf Rng.Value = "No" Then
Rows("90:121").EntireRow.Hidden = True
Range("E89").Select
End If
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row < 88 Then
If Target.Row < 89 Then
Exit Sub
ElseIf Target.Column < 5 Then
Exit Sub
End If
HideRows2
ElseIf Target.Column < 5 Then
Exit Sub
End If

HideRows1
End Sub

daidipya wrote:
This is the code at present

Sub HideRows1()
Dim Rng As Range
Set Rng = Sheets("input-assumptions").Range("E88")
If Rng.Value = "Yes" Then
Rows("89:89").EntireRow.Hidden = False
Range("E89").Select
ElseIf Rng.Value = "No" Then
Rows("89:122").EntireRow.Hidden = True
Range("E88").Select
End If
End Sub

Sub HideRows2()
Dim Rng As Range
Set Rng = Sheets("input-assumptions").Range("E89")
If Rng.Value = "Yes" Then
Rows("90:122").EntireRow.Hidden = False
Range("E89").Select
ElseIf Rng.Value = "No" Then
Rows("90:121").EntireRow.Hidden = True
Range("E89").Select
End If
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row < 88 Then Exit Sub
If Target.Column < 5 Then Exit Sub
HideRows1
If Target.Row < 89 Then Exit Sub
If Target.Column < 5 Then Exit Sub
HideRows2
End Sub

however to run the HideRows2 macro i need to run the macro from the
tools macro - tab of the excel, while the HideRows1 macro runs on
automatically on slection of Yes or No

Please help me


  #3   Report Post  
Posted to microsoft.public.excel.misc
daidipya
 
Posts: n/a
Default Want to run two macros without errors

thanks

but i am unable to understand the logic. Is there any way by whcih i
can have different Private Sub Worksheet_Change(ByVal Target As Range)
for different macros.

wrote:
Please change the code to the following

Sub HideRows1()
Dim Rng As Range
Set Rng = Sheets("input-assumptions").Range("E88")
If Rng.Value = "Yes" Then
Rows("89:89").EntireRow.Hidden = False
Range("E89").Select
ElseIf Rng.Value = "No" Then
Rows("89:122").EntireRow.Hidden = True
Range("E88").Select
End If
End Sub

Sub HideRows2()
Dim Rng As Range
Set Rng = Sheets("input-assumptions").Range("E89")
If Rng.Value = "Yes" Then
Rows("90:122").EntireRow.Hidden = False
Range("E89").Select
ElseIf Rng.Value = "No" Then
Rows("90:121").EntireRow.Hidden = True
Range("E89").Select
End If
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row < 88 Then
If Target.Row < 89 Then
Exit Sub
ElseIf Target.Column < 5 Then
Exit Sub
End If
HideRows2
ElseIf Target.Column < 5 Then
Exit Sub
End If

HideRows1
End Sub

daidipya wrote:
This is the code at present

Sub HideRows1()
Dim Rng As Range
Set Rng = Sheets("input-assumptions").Range("E88")
If Rng.Value = "Yes" Then
Rows("89:89").EntireRow.Hidden = False
Range("E89").Select
ElseIf Rng.Value = "No" Then
Rows("89:122").EntireRow.Hidden = True
Range("E88").Select
End If
End Sub

Sub HideRows2()
Dim Rng As Range
Set Rng = Sheets("input-assumptions").Range("E89")
If Rng.Value = "Yes" Then
Rows("90:122").EntireRow.Hidden = False
Range("E89").Select
ElseIf Rng.Value = "No" Then
Rows("90:121").EntireRow.Hidden = True
Range("E89").Select
End If
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row < 88 Then Exit Sub
If Target.Column < 5 Then Exit Sub
HideRows1
If Target.Row < 89 Then Exit Sub
If Target.Column < 5 Then Exit Sub
HideRows2
End Sub

however to run the HideRows2 macro i need to run the macro from the
tools macro - tab of the excel, while the HideRows1 macro runs on
automatically on slection of Yes or No

Please help me


  #4   Report Post  
Posted to microsoft.public.excel.misc
 
Posts: n/a
Default Want to run two macros without errors

No.
You can have only one Worksheet_Change sub per worksheet.
The logic is just trying to do the following steps.
1. Is the row number 88, if Yes then is it Column number 5, if Yes
then Hiderows1 else just exit.
2. If the row number is not 88 then is it 89, if Yes then is Column
number 5, if Yes then Hiderows2 else just exit


daidipya wrote:
thanks

but i am unable to understand the logic. Is there any way by whcih i
can have different Private Sub Worksheet_Change(ByVal Target As Range)
for different macros.

wrote:
Please change the code to the following

Sub HideRows1()
Dim Rng As Range
Set Rng = Sheets("input-assumptions").Range("E88")
If Rng.Value = "Yes" Then
Rows("89:89").EntireRow.Hidden = False
Range("E89").Select
ElseIf Rng.Value = "No" Then
Rows("89:122").EntireRow.Hidden = True
Range("E88").Select
End If
End Sub

Sub HideRows2()
Dim Rng As Range
Set Rng = Sheets("input-assumptions").Range("E89")
If Rng.Value = "Yes" Then
Rows("90:122").EntireRow.Hidden = False
Range("E89").Select
ElseIf Rng.Value = "No" Then
Rows("90:121").EntireRow.Hidden = True
Range("E89").Select
End If
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row < 88 Then
If Target.Row < 89 Then
Exit Sub
ElseIf Target.Column < 5 Then
Exit Sub
End If
HideRows2
ElseIf Target.Column < 5 Then
Exit Sub
End If

HideRows1
End Sub

daidipya wrote:
This is the code at present

Sub HideRows1()
Dim Rng As Range
Set Rng = Sheets("input-assumptions").Range("E88")
If Rng.Value = "Yes" Then
Rows("89:89").EntireRow.Hidden = False
Range("E89").Select
ElseIf Rng.Value = "No" Then
Rows("89:122").EntireRow.Hidden = True
Range("E88").Select
End If
End Sub

Sub HideRows2()
Dim Rng As Range
Set Rng = Sheets("input-assumptions").Range("E89")
If Rng.Value = "Yes" Then
Rows("90:122").EntireRow.Hidden = False
Range("E89").Select
ElseIf Rng.Value = "No" Then
Rows("90:121").EntireRow.Hidden = True
Range("E89").Select
End If
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Row < 88 Then Exit Sub
If Target.Column < 5 Then Exit Sub
HideRows1
If Target.Row < 89 Then Exit Sub
If Target.Column < 5 Then Exit Sub
HideRows2
End Sub

however to run the HideRows2 macro i need to run the macro from the
tools macro - tab of the excel, while the HideRows1 macro runs on
automatically on slection of Yes or No

Please help me


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
Hide Macro's in Toolbar / Macro's list sparx Excel Discussion (Misc queries) 2 May 6th 06 08:53 PM
Tracking Errors Karen Excel Worksheet Functions 1 April 6th 06 01:34 PM
how do I run excel 4.0 macros on excel 2000 RodolfoDallas Excel Discussion (Misc queries) 1 March 12th 06 03:14 AM
Excel crashes while opening excel file imbeddied with macros ct2147 Excel Discussion (Misc queries) 0 December 30th 05 09:05 PM
macros errors Natalie Excel Worksheet Functions 5 March 14th 05 02:27 PM


All times are GMT +1. The time now is 09:17 PM.

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"