JohnZ1156
Board Regular
- Joined
- Apr 10, 2021
- Messages
- 180
- Office Version
- 2021
- Platform
- Windows
I have a macro that I would like to be able to run on different worksheets. I placed a "button" on Sheet1 and assigned this macro:
Problem is, I'd like to place the same button on Sheet2, Sheet3, etc. and run the same macro, except on the current sheet, not always on Sheet1.
I know the "fix" is somewhere in the line Set ws = Worksheets("Sheet1") but I don't know how to "fix" it.
Problem is, I'd like to place the same button on Sheet2, Sheet3, etc. and run the same macro, except on the current sheet, not always on Sheet1.
I know the "fix" is somewhere in the line Set ws = Worksheets("Sheet1") but I don't know how to "fix" it.
VBA Code:
Option Explicit
Sub L_to_R()
Application.ScreenUpdating = False
Dim ws As Worksheet, c As Range
Set ws = Worksheets("Sheet1")
For Each c In ws.Range("A2", Cells(Rows.Count, "A").End(xlUp))
If IsDate(c) Then c.Offset(, 1).Resize(, 5).Sort _
Key1:=c, Order1:=xlAscending, Orientation:=xlLeftToRight
ws.Sort.SortFields.Clear
Next c
Application.ScreenUpdating = True
End Sub