Hi,
I am trying to have excel autimatically sort a worksheet with columns A-F by the dates in column E, oldest to newest. I want to be able to add information in new rows and have it sort with the rest of the worksheet when I save.
Thanks
Hi,
I am trying to have excel autimatically sort a worksheet with columns A-F by the dates in column E, oldest to newest. I want to be able to add information in new rows and have it sort with the rest of the worksheet when I save.
Thanks
Try this (change sheet name):
![]()
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) Sheets("Sheet1").Range("A1").CurrentRegion.Sort Key1:=Range("E1"), Order1:=xlAscending, Header:= _ xlYes, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortTextAsNumbers End Sub
The code needs to go on the ThisWorkbook page of your workbook's VBA project.
Dom
"May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."
Use code tags when posting your VBA code: [code] Your code here [/code]
Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.
Thanks so much!
I also would like to make it so when I enter any data in, it automatically copies to sheet2, but I don't want sheet 2 to auto sort column E as sheet1 does.
Can someone help me out with this?
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks