Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 239
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 857
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create a macro so when I click the icon, the response is the A1 ce Winnipeg Michael Excel Discussion (Misc queries) 10 September 11th 08 03:06 PM
Create a macro that finds values then sorts John Hughes Excel Worksheet Functions 2 August 30th 06 12:10 AM
create a macro to save excel sheet Moussa Hawas Excel Worksheet Functions 1 October 16th 05 09:19 PM
How do I save & apply sorts subtotals in excel to new worksheets? Kent Excel Discussion (Misc queries) 2 July 13th 05 12:53 AM
How do I create a macro to Save As? Shelly9633 Excel Discussion (Misc queries) 3 December 3rd 04 05:38 PM


All times are GMT +1. The time now is 02:29 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"