Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,538
- Office Version
- 365
- 2016
- Platform
- Windows
Consider this code:
This code is executed with a button push on sheet1 of the workbook. I'd prefer to keep sheet1 in focus while this code is being executed. The only way I can run this code without running into an error ("The sort reference is not valid. Make sure that it's within the data you want to sort, and the first Sort By box isn't the same or blank") , is to add the ".activate". But when I do that, the focus leaves sheet1 to go to worksheet "Dynamic". I don't want this.
Code:
Sub file_listing()
With Worksheets("DYNAMIC")
.Activate
.Range("A2:A" & i + 1).Sort key1:=Range("A2"), Order1:=xlDescending, Header:=xlGuess
End With
End Sub
This code is executed with a button push on sheet1 of the workbook. I'd prefer to keep sheet1 in focus while this code is being executed. The only way I can run this code without running into an error ("The sort reference is not valid. Make sure that it's within the data you want to sort, and the first Sort By box isn't the same or blank") , is to add the ".activate". But when I do that, the focus leaves sheet1 to go to worksheet "Dynamic". I don't want this.