I used the recorder to create a macro on 'Sheet2' and it works flawlessly. Then I created a command button on 'Sheet 1' to run the macro on 'Sheet 2'.
Unfortunately, when I click the command button, it only runs on 'Sheet 1'. I tried using the select sheets("Sheet2").activate code, but it wasn't working. I've listed the code below. Can you please help? Thanks in advance.
Sub MMkt_Analysis_Tab()
'
' MMkt_Analysis_Tab Macro
'
'
Rows("24:42").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A6:M23").Select
Selection.Copy
Range("A25").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Selection.Font.Underline = xlUnderlineStyleDouble
Selection.Font.Underline = xlUnderlineStyleNone
Rows("25:27").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Font.Bold = True
Range("A27:M27").Select
Selection.Font.Underline = xlUnderlineStyleSingle
Selection.Font.Underline = xlUnderlineStyleNone
Range("A27,C27,E27,G27,I27,K27,M27").Select
Range("M27").Activate
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Selection.Borders(xlEdgeTop).LineStyle = xlNone
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Range("C40,E40,G40,I40,K40,M40").Select
Range("M40").Activate
Selection.Font.Underline = xlUnderlineStyleSingleAccounting
Range("C42,E42,G42,I42,K42,M42").Select
Range("M42").Activate
Selection.Font.Underline = xlUnderlineStyleDoubleAccounting
End Sub
Unfortunately, when I click the command button, it only runs on 'Sheet 1'. I tried using the select sheets("Sheet2").activate code, but it wasn't working. I've listed the code below. Can you please help? Thanks in advance.
Sub MMkt_Analysis_Tab()
'
' MMkt_Analysis_Tab Macro
'
'
Rows("24:42").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A6:M23").Select
Selection.Copy
Range("A25").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Selection.Font.Underline = xlUnderlineStyleDouble
Selection.Font.Underline = xlUnderlineStyleNone
Rows("25:27").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Font.Bold = True
Range("A27:M27").Select
Selection.Font.Underline = xlUnderlineStyleSingle
Selection.Font.Underline = xlUnderlineStyleNone
Range("A27,C27,E27,G27,I27,K27,M27").Select
Range("M27").Activate
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Selection.Borders(xlEdgeTop).LineStyle = xlNone
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Range("C40,E40,G40,I40,K40,M40").Select
Range("M40").Activate
Selection.Font.Underline = xlUnderlineStyleSingleAccounting
Range("C42,E42,G42,I42,K42,M42").Select
Range("M42").Activate
Selection.Font.Underline = xlUnderlineStyleDoubleAccounting
End Sub