Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-27-2010, 10:28 PM
Ziggy-R Ziggy-R is offline Macro for automatic sorting Windows XP Macro for automatic sorting Office 2003
Novice
Macro for automatic sorting
 
Join Date: Sep 2010
Posts: 13
Ziggy-R is on a distinguished road
Smile Macro for automatic sorting

Afternoon, guys.



So, I have a purchase order spreadsheet, which gets a handful of new entries every day, and a few removed every day. Since it's constantly getting updated, I'd like to include a macro that would automatically sort all the content by "Supplier". Having essentially zero experience with macros, I don't even know where to start; could anybody help me out?

Cheers in advance.
Reply With Quote
  #2  
Old 09-28-2010, 12:42 PM
BjornS BjornS is offline Macro for automatic sorting Windows Vista Macro for automatic sorting Office 2003
Competent Performer
 
Join Date: Jan 2010
Location: Sweden
Posts: 116
BjornS is on a distinguished road
Default

Hi,
if this issue is still open, please attach an example with an explanation what you want to achieve. This is perhaps possible to solve without a macro.

Kind regards
Bjorn
Reply With Quote
  #3  
Old 09-28-2010, 05:25 PM
Ziggy-R Ziggy-R is offline Macro for automatic sorting Windows XP Macro for automatic sorting Office 2003
Novice
Macro for automatic sorting
 
Join Date: Sep 2010
Posts: 13
Ziggy-R is on a distinguished road
Default

Quote:
Originally Posted by BjornS View Post
Hi,
if this issue is still open, please attach an example with an explanation what you want to achieve. This is perhaps possible to solve without a macro.

Kind regards
Bjorn
I want this spreadsheet to automatically sort data by "Supplier" every time I open it.
Attached Images
File Type: jpg untitled.JPG (142.6 KB, 22 views)
Reply With Quote
  #4  
Old 09-28-2010, 09:03 PM
icurf8now's Avatar
icurf8now icurf8now is offline Macro for automatic sorting Windows XP Macro for automatic sorting Office 2003
Novice
 
Join Date: Sep 2010
Location: Where Toto came from
Posts: 3
icurf8now is on a distinguished road
Default

Can't you just make a macro with the sort by 'supplier' and just run the macro?
Reply With Quote
  #5  
Old 09-28-2010, 09:07 PM
Ziggy-R Ziggy-R is offline Macro for automatic sorting Windows XP Macro for automatic sorting Office 2003
Novice
Macro for automatic sorting
 
Join Date: Sep 2010
Posts: 13
Ziggy-R is on a distinguished road
Default

Quote:
Originally Posted by icurf8now View Post
Can't you just make a macro with the sort by 'supplier' and just run the macro?
That's exactly what I want to do, but I don't know how. I've got virtually no experience with macros.

Edit: Actually, that's exactly what my code does now. It sorts the data alright when I manually run the macro, but doesn't do it when I set it to AutoOpen or AutoExit. Any ideas?

Last edited by Ziggy-R; 09-29-2010 at 01:48 AM.
Reply With Quote
  #6  
Old 09-29-2010, 10:54 AM
Kimberly Kimberly is offline Macro for automatic sorting Windows 7 Macro for automatic sorting Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Posts: 517
Kimberly is on a distinguished road
Default

Why don't you select a cell in the Supplier column and click the Sort button? How would a macro improve on that?
Reply With Quote
  #7  
Old 09-30-2010, 05:21 PM
Ziggy-R Ziggy-R is offline Macro for automatic sorting Windows XP Macro for automatic sorting Office 2003
Novice
Macro for automatic sorting
 
Join Date: Sep 2010
Posts: 13
Ziggy-R is on a distinguished road
Default

Quote:
Originally Posted by Kimberly View Post
Why don't you select a cell in the Supplier column and click the Sort button? How would a macro improve on that?
Uh. Because it would automate it? One less step to have to do each time? Since it gets a whole heap of additions a day, it gets out of order quickly, so I want the macro to sort the spreadsheet by supplier upon opening/closing, so it's kept in order without me having to manually order it. Isn't this the point of macros?
Reply With Quote
  #8  
Old 10-01-2010, 04:04 AM
Kimberly Kimberly is offline Macro for automatic sorting Windows 7 Macro for automatic sorting Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Posts: 517
Kimberly is on a distinguished road
Default

Uh. I thought perhaps you were unaware that all you have to do is select one cell and click one button. Some people sort using a longer technique.
Reply With Quote
  #9  
Old 10-02-2010, 08:22 AM
BjornS BjornS is offline Macro for automatic sorting Windows Vista Macro for automatic sorting Office 2003
Competent Performer
 
Join Date: Jan 2010
Location: Sweden
Posts: 116
BjornS is on a distinguished road
Default

Hi,
I am more a "formula expert", but I looked around a little, stole some code and modified it

Here we go:
Right click the sheet tab. Select "View code".
Paste the code below. Modify sort column if wanted (A1 at the moment). Leave with Alt+Q.
Done!

Kind regards
Bjorn

Private Sub Worksheet_Change(ByVal Target As Range)
'Sort this sheet by column A
'Written by OzGrid Business Applications
'www.ozgrid.com
'small modification by Bjorn 2010-10-02

On Error Resume Next
Application.EnableEvents = False
Me.UsedRange.Sort _
Key1:=[A1], Order1:=xlAscending, Header:=xlYes, Orientation:=xlSortColumns
Application.EnableEvents = True
On Error GoTo 0

End Sub
Reply With Quote
  #10  
Old 10-03-2010, 05:17 PM
Ziggy-R Ziggy-R is offline Macro for automatic sorting Windows XP Macro for automatic sorting Office 2003
Novice
Macro for automatic sorting
 
Join Date: Sep 2010
Posts: 13
Ziggy-R is on a distinguished road
Default

Quote:
Originally Posted by BjornS View Post
Hi,
I am more a "formula expert", but I looked around a little, stole some code and modified it

Here we go:
Right click the sheet tab. Select "View code".
Paste the code below. Modify sort column if wanted (A1 at the moment). Leave with Alt+Q.
Done!

Kind regards
Bjorn

Private Sub Worksheet_Change(ByVal Target As Range)
'Sort this sheet by column A
'Written by OzGrid Business Applications
'www.ozgrid.com
'small modification by Bjorn 2010-10-02

On Error Resume Next
Application.EnableEvents = False
Me.UsedRange.Sort _
Key1:=[A1], Order1:=xlAscending, Header:=xlYes, Orientation:=xlSortColumns
Application.EnableEvents = True
On Error GoTo 0

End Sub

No luck, man. Maybe it's because I didn't change the sort column (How do I?), but upon opening and closing, all the data remains the same.
Reply With Quote
  #11  
Old 10-04-2010, 02:07 PM
BjornS BjornS is offline Macro for automatic sorting Windows Vista Macro for automatic sorting Office 2003
Competent Performer
 
Join Date: Jan 2010
Location: Sweden
Posts: 116
BjornS is on a distinguished road
Default

Hi,
try replacing A1 with C1 in the macro, since you like to sort column C (which contains the supplier).

Kind regards
Bjorn
Reply With Quote
  #12  
Old 10-04-2010, 03:18 PM
Kimberly Kimberly is offline Macro for automatic sorting Windows 7 Macro for automatic sorting Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Posts: 517
Kimberly is on a distinguished road
Default

If you already have a macro that works, but just need for it to run when the file is opened, change the first line of the macro to

Sub Auto_Open()

Instead of Sub Whatever it is currently named

Alternatively, turn on macro recorder and make sure the Use Relative References button is off (it probably is). Name the macro Macro99. Select a cell in column C. Click either sort ascending or sort descending on the toolbar. Stop recording.

Tools > Macro > View macros
Select Macro99 and click Edit button
Change the first line, which is currently Sub Macro99()
to
Sub Auto_Open()
Reply With Quote
  #13  
Old 10-04-2010, 05:19 PM
Ziggy-R Ziggy-R is offline Macro for automatic sorting Windows XP Macro for automatic sorting Office 2003
Novice
Macro for automatic sorting
 
Join Date: Sep 2010
Posts: 13
Ziggy-R is on a distinguished road
Default

Okay guys, I think I've figured out the problem. The macro is working fine, but the reason it wasn't sorting the new additions (and still isn't) is because it only sets the range to whatever it was when I record the macro. As soon as I add in new orders, the range changes and the macro doesn't sort them all.

Pic attached is what I mean. If I set the macro while I've got Example 1 to 15, then add in 16 later, it'll only sort 1 to 15 upon opening. Any ideas, guys?
Attached Images
File Type: jpg howdoifixtherange.JPG (169.1 KB, 14 views)
Reply With Quote
  #14  
Old 10-04-2010, 06:57 PM
ConneXionLost's Avatar
ConneXionLost ConneXionLost is offline Macro for automatic sorting Windows XP Macro for automatic sorting Office 2003
Simulacrum
 
Join Date: Jan 2010
Location: Victoria, Canada
Posts: 86
ConneXionLost is on a distinguished road
Default

Consider using Dynamic Named Ranges to identify the area you want to sort.

Cheers,
Reply With Quote
Reply

Tags
macro, sort



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro for automatic sorting Sorting question markg2 Excel 4 01-25-2010 03:13 PM
automatic start of macro + help on writing helper function vsempoux Word 3 10-09-2009 03:01 AM
Sorting Outlook TO: field anakeimai Outlook 0 09-30-2009 06:15 AM
Sorting Tasks by Contacts Bat Outlook 0 09-24-2007 01:20 PM
sheet linking, sorting nickbfe Excel 0 05-19-2006 11:00 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:21 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft