Need help with macro
I have the following macro that someone made for me a few years ago. In it, it is tied to a certain page. I need to be able to run the macro on the page that I am working on without having to change the page name every time.
Sub Macro1()
‘
‘ Macro1 Macro
‘
‘
Range(“A8”).Select
Range(Selection, Selection.End(xlDown)).Select
Range(“A8:I41”).Select
ActiveWorkbook.Worksheets(“June 2024”).Sort.SortFields.Clear
ActiveWorkbook.Worksheets(“June 2024”).Sort.SortFields.Add2 Key:=Range( _
“E7:E41”), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
ActiveWorkbook.Worksheets(“June 2024”).Sort.SortFields.Add2 Key:=Range( _
“A8:A41”), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets(“June 2024”).Sort
.SetRange Range(“A8:I41”)
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
Dim i As Integer
For i = 2 To 5000
If Cells(i, 5).Value <> Cells(i + 1, 5).Value Then
Cells(i + 1, 5).Rows(“1:1”).EntireRow.Insert
i = i + 1
Else
End If
Next i
End With
End Sub
I have the following macro that someone made for me a few years ago. In it, it is tied to a certain page. I need to be able to run the macro on the page that I am working on without having to change the page name every time. Sub Macro1()” Macro1 Macro”Range(“A8”).SelectRange(Selection, Selection.End(xlDown)).SelectRange(“A8:I41”).SelectActiveWorkbook.Worksheets(“June 2024”).Sort.SortFields.ClearActiveWorkbook.Worksheets(“June 2024″).Sort.SortFields.Add2 Key:=Range( _”E7:E41”), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _xlSortNormalActiveWorkbook.Worksheets(“June 2024″).Sort.SortFields.Add2 Key:=Range( _”A8:A41”), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _xlSortNormalWith ActiveWorkbook.Worksheets(“June 2024”).Sort.SetRange Range(“A8:I41”).Header = xlGuess.MatchCase = False.Orientation = xlTopToBottom.SortMethod = xlPinYin.Apply Dim i As IntegerFor i = 2 To 5000If Cells(i, 5).Value <> Cells(i + 1, 5).Value ThenCells(i + 1, 5).Rows(“1:1”).EntireRow.Inserti = i + 1ElseEnd IfNext iEnd WithEnd Sub Read More