Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
How to create a macro that sorts data when I click save?
I need help creating a macro that sorts the data in sheet#2 at cell B1 as
Descending "from Z to A" when I click on Save. normally, I only click save when I'm done with the file, so it doesn't matter if the macro activates only if I click save, but something similar also works. because sorted data doesn't update when the values change for what ever reason, I have to click on Sort Descending each time I update the data. and I want to automate it using a macro. I have posted earlier a question "why Sort Descending does not refresh?" and I got an answer that I can do that using a macro, but I don't have skill in VB to do it myself. please assist. |
#2
Posted to microsoft.public.excel.misc
|
|||
|
|||
How to create a macro that sorts data when I click save?
On Nov 10, 8:53*am, Abdul wrote:
I need help creating a macro that sorts the data in sheet#2 at cell B1 as Descending "from Z to A" when I click on Save. normally, I only click save when I'm done with the file, so it doesn't matter if the macro activates only if I click save, but something similar also works. because sorted data doesn't update when the values change for what ever reason, I have to click on Sort Descending each time I update the data. and I want to automate it using a macro. I have posted earlier a question "why Sort Descending does not refresh?" and I got an answer that I can do that using a macro, but I don't have skill in VB to do it myself. please assist. Abdul, You have posted in wrong group. But here is your macro. Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) Sheets("SHEET2").Select Range("B1").Select Selection.Sort Key1:=Range("B2"), Order1:=xlDescending, Header:=xlYes, _ OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _ DataOption1:=xlSortNormal End Sub copy paste above macro in thisworkbook in your VBA editor. Also try to use macro recorder which will surely help you to get started. Hope this helps. Regards, Madiya |
#3
Posted to microsoft.public.excel.misc
|
|||
|
|||
How to create a macro that sorts data when I click save?
Hi,
1. Record the sort command 2. Add the code to the Workbook_BeforeSave event. You can find this event in the VBE by double-clicking the thisWorkbook object in the Projects window and pick Workbook from the Object dropdown at the top left in the code window, and BeforeSave from the procedure drop down at the top right of the code window. Paste your code into this procedure. If this helps, please click the Yes button. "Abdul" wrote in message ... I need help creating a macro that sorts the data in sheet#2 at cell B1 as Descending "from Z to A" when I click on Save. normally, I only click save when I'm done with the file, so it doesn't matter if the macro activates only if I click save, but something similar also works. because sorted data doesn't update when the values change for what ever reason, I have to click on Sort Descending each time I update the data. and I want to automate it using a macro. I have posted earlier a question "why Sort Descending does not refresh?" and I got an answer that I can do that using a macro, but I don't have skill in VB to do it myself. please assist. |
#4
Posted to microsoft.public.excel.misc
|
|||
|
|||
How to create a macro that sorts data when I click save?
"Madiya" wrote: Abdul, You have posted in wrong group. I'm new to this community, please redirect me to where I should've posted this, but thanks for your help. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Create a macro so when I click the icon, the response is the A1 ce | Excel Discussion (Misc queries) | |||
Create a macro that finds values then sorts | Excel Worksheet Functions | |||
create a macro to save excel sheet | Excel Worksheet Functions | |||
How do I save & apply sorts subtotals in excel to new worksheets? | Excel Discussion (Misc queries) | |||
How do I create a macro to Save As? | Excel Discussion (Misc queries) |