Hi,
I am facing some difficulty with running multiple macros in multiple worksheets. This might be simple, and I searched quite alot, but couldn't find the answer that I am looking for. I am be very grateful if someone can help with this!
The <acronym title="visual basic for applications" style="border-width: 0px 0px 1px; border-bottom-style: dotted; border-bottom-color: rgb(0, 0, 0); cursor: help; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);">VBA</acronym> code that I tried is not working.
So I have one workbook (that is one Excel document). There are two sheets, Sheet 1 and Sheet 2. I have three Macros, Macro 1, 2 and 3.
I want to run Macro 1 and 2 in Sheet 1 and Macro 3 in Sheet 2. Hence, I want to create a <acronym title="visual basic for applications" style="border-width: 0px 0px 1px; border-bottom-style: dotted; border-bottom-color: rgb(0, 0, 0); cursor: help; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);">VBA</acronym> code which first runs Macro 1 and then Macro 2 in Sheet 1 and then Macro 3 in Sheet 2.
I thought I have to use the worksheet.Activate command but it doesn't seem to be working. I used the following code:
Private Sub Worksheet_Change(ByVal Target As Range)
Sheets("Sheet1").Activate
Select Case Target.Column
Case Is = 4, 5, 6, 7
Call Macro1
Call Macro2
End Select
Sheets("Sheet2").Activate
Call Macro3
End Sub
Sheet 1 seems to be working with Macro 1 and 2 but then it doesn't go to Sheet 2 and does not run Macro 3.
So basically even by using the above code, the only part that it is running is:
Private Sub Worksheet_Change(ByVal Target As Range)
Sheets("Sheet1").Activate
Select Case Target.Column
Case Is = 4, 5, 6, 7
Call Macro1
Call Macro2
End Select
End Sub
Maybe there is a problem with the 'module' where I'm creating the above code.
In order to create Macro 1 and Macro 2, I right-clicked on 'Sheet1' in the left hand side panel in <acronym title="visual basic for applications" style="border-width: 0px 0px 1px; border-bottom-style: dotted; border-bottom-color: rgb(0, 0, 0); cursor: help; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);">VBA</acronym>, insert>module.
Same for Macro 3, I right-clicked on 'Sheet 2' and insert>module.
But for running the above code which combines macros from both sheets, which module should I use, where should I right-click or double-click to create a module, <acronym title="visual basic for applications" style="border-width: 0px 0px 1px; border-bottom-style: dotted; border-bottom-color: rgb(0, 0, 0); cursor: help; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);">VBA</acronym> Project (Workbook1) or thisworkbook?
What is the correct code that I should be using?
I am facing some difficulty with running multiple macros in multiple worksheets. This might be simple, and I searched quite alot, but couldn't find the answer that I am looking for. I am be very grateful if someone can help with this!
The <acronym title="visual basic for applications" style="border-width: 0px 0px 1px; border-bottom-style: dotted; border-bottom-color: rgb(0, 0, 0); cursor: help; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);">VBA</acronym> code that I tried is not working.
So I have one workbook (that is one Excel document). There are two sheets, Sheet 1 and Sheet 2. I have three Macros, Macro 1, 2 and 3.
I want to run Macro 1 and 2 in Sheet 1 and Macro 3 in Sheet 2. Hence, I want to create a <acronym title="visual basic for applications" style="border-width: 0px 0px 1px; border-bottom-style: dotted; border-bottom-color: rgb(0, 0, 0); cursor: help; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);">VBA</acronym> code which first runs Macro 1 and then Macro 2 in Sheet 1 and then Macro 3 in Sheet 2.
I thought I have to use the worksheet.Activate command but it doesn't seem to be working. I used the following code:
Private Sub Worksheet_Change(ByVal Target As Range)
Sheets("Sheet1").Activate
Select Case Target.Column
Case Is = 4, 5, 6, 7
Call Macro1
Call Macro2
End Select
Sheets("Sheet2").Activate
Call Macro3
End Sub
Sheet 1 seems to be working with Macro 1 and 2 but then it doesn't go to Sheet 2 and does not run Macro 3.
So basically even by using the above code, the only part that it is running is:
Private Sub Worksheet_Change(ByVal Target As Range)
Sheets("Sheet1").Activate
Select Case Target.Column
Case Is = 4, 5, 6, 7
Call Macro1
Call Macro2
End Select
End Sub
Maybe there is a problem with the 'module' where I'm creating the above code.
In order to create Macro 1 and Macro 2, I right-clicked on 'Sheet1' in the left hand side panel in <acronym title="visual basic for applications" style="border-width: 0px 0px 1px; border-bottom-style: dotted; border-bottom-color: rgb(0, 0, 0); cursor: help; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);">VBA</acronym>, insert>module.
Same for Macro 3, I right-clicked on 'Sheet 2' and insert>module.
But for running the above code which combines macros from both sheets, which module should I use, where should I right-click or double-click to create a module, <acronym title="visual basic for applications" style="border-width: 0px 0px 1px; border-bottom-style: dotted; border-bottom-color: rgb(0, 0, 0); cursor: help; color: rgb(51, 51, 51); background-color: rgb(250, 250, 250);">VBA</acronym> Project (Workbook1) or thisworkbook?
What is the correct code that I should be using?