How to Combine two Macros

keranali

Rules Violation
Joined
Oct 4, 2010
Messages
234
Office Version
  1. 365
Platform
  1. Windows
Hi everyone how do you join two macros into one I have macro 1


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim LastRw As Long, ThisRw As Long

LastRw = Range("A" & Rows.Count).End(xlUp).Row
If Intersect(ActiveCell, Range("A2:I" & LastRw)) Is Nothing Then
Range("w3:w5,w8:w11").ClearContents
Else
ThisRw = ActiveCell.Row
Range("w3:w5").Value = Application.Transpose(Cells(ThisRw, "G").Resize(, 3).Value)
Range("w8:w12").Value = Application.Transpose(Cells(ThisRw, "B").Resize(, 5).Value)
End If
End Sub




And macro 2

Sub Uppercase()
' Loop to cycle through each cell in the specified range.
For Each x In Range("A1:A5")
' Change the text in the range to uppercase letters.
x.Value = UCase(x.value)
Next
End Sub


I needed both of them to work on the same sheet?

Thanks
K
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Hi,

Do you mean when you run the first macro it should also run the second automatically? If so:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim LastRw As Long, ThisRw As Long
    
        LastRw = Range("A" & Rows.Count).End(xlUp).Row
        If Intersect(ActiveCell, Range("A2:I" & LastRw)) Is Nothing Then
            Range("w3:w5,w8:w11").ClearContents
        Else
            ThisRw = ActiveCell.Row
            Range("w3:w5").Value = Application.Transpose(Cells(ThisRw, "G").Resize(, 3).Value)
            Range("w8:w12").Value = Application.Transpose(Cells(ThisRw, "B").Resize(, 5).Value)
        End If
    [B]Uppercase[/B]
End Sub
 
Upvote 0
Hi thanks for your reply however its more like merging two into one to run real time once excel opens.
The both starts automatically independent but I needed them merged.
Thanks
K
 
Upvote 0
Hi,

Not sure exactly what you mean. You want them both to run at the same time once Excel opens? - If this is true then macro 1 only works when you change something in a cell.

'Merging' them (adding macro 2 into macro 1) is the same as what I posted.
 
Upvote 0
Hi thanks for your reply however its more like merging two into one to run real time once excel opens.
The both starts automatically independent but I needed them merged.
Thanks
K

Maybe calling the second macro???

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim LastRw As Long, ThisRw As Long

LastRw = Range("A" & Rows.Count).End(xlUp).Row
If Intersect(ActiveCell, Range("A2:I" & LastRw)) Is Nothing Then
Range("w3:w5,w8:w11").ClearContents
Else
ThisRw = ActiveCell.Row
Range("w3:w5").Value = Application.Transpose(Cells(ThisRw, "G").Resize(, 3).Value)
Range("w8:w12").Value = Application.Transpose(Cells(ThisRw, "B").Resize(, 5).Value)
End If
End Sub

Call Uppercase
 
Upvote 0
Hi Guys I dont understand "Call Uppercase" what is ment by call uppercase
 
Upvote 0
Ok so then it will be like this?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim LastRw As Long, ThisRw As Long

LastRw = Range("A" & Rows.Count).End(xlUp).Row
If Intersect(ActiveCell, Range("A2:I" & LastRw)) Is Nothing Then
Range("w3:w5,w8:w11").ClearContents
Else
ThisRw = ActiveCell.Row
Range("w3:w5").Value = Application.Transpose(Cells(ThisRw, "G").Resize(, 3).Value)
Range("w8:w12").Value = Application.Transpose(Cells(ThisRw, "B").Resize(, 5).Value)
End If
End Sub

Call uppercase
Sub Uppercase()
' Loop to cycle through each cell in the specified range.
For Each x In Range("A1:A5")
' Change the text in the range to uppercase letters.
x.Value = UCase(x.value)
Next
End Sub
 
Upvote 0
Ok so then it will be like this?

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim LastRw As Long, ThisRw As Long

LastRw = Range("A" & Rows.Count).End(xlUp).Row
If Intersect(ActiveCell, Range("A2:I" & LastRw)) Is Nothing Then
Range("w3:w5,w8:w11").ClearContents
Else
ThisRw = ActiveCell.Row
Range("w3:w5").Value = Application.Transpose(Cells(ThisRw, "G").Resize(, 3).Value)
Range("w8:w12").Value = Application.Transpose(Cells(ThisRw, "B").Resize(, 5).Value)
End If
End Sub

Call uppercase
Sub Uppercase()
' Loop to cycle through each cell in the specified range.
For Each x In Range("A1:A5")
' Change the text in the range to uppercase letters.
x.Value = UCase(x.value)
Next
End Sub

As of right now, you have two separate macro's, correct? If so, copy the code I posted above exactly the way I did. Once "Macro 1" is through running it will automatically run "Macro 2".
 
Upvote 0
Hi I am getting a compile error, where do I insert the second macro below "call Uppercase"
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,277
Members
452,902
Latest member
Knuddeluff

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top