Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Dead Pressed
Nov 11, 2009
This is probably too simple for this place (or the incorrect location, sorry!), but I have an excel macro question to ask of you all.

I'm working on a wedding list in excel, and there's some sorting functionality I'm trying to macro and assign to a big button for my fiancee. Basically, the list has these headers:

Lastname, family designation, head of household, firstname, party invite, party rsvp, wedding invite, wedding rsvp

Click here for the full 1104x137 image.


Basically, the goal is for the macro to sort last name first, then order members of different families with same name (ie, jones) by a numerical designation (jones 1, jones 2), then it will place heads of the households at the top of the list (for that specfic name) so they can appropriately be addressed in the invitations, then sorted lastly sorted alphabetically by first name. I've got it set up so we can also filter from the headers so that my fiancee and check off people who've gotten invites to the party/wedding, and then filter the list to see who needs what, and how many are coming, etc.

TLDR So, now the point. I can go through the sorting steps fine myself, and everything works how I intend. I then go to record the macro in excel, and it works, but as soon as more names are added, the macro does not work. It may work randomly after mashing the hotkeys a thousand times, or they may not. Does anybody any idea what may be happening?

*This is crossposted in the Small Q megathread. I didn't realize there was an up to date one for excel, as the one in the megathread was dead. :(*

Adbot
ADBOT LOVES YOU

Dead Pressed
Nov 11, 2009

ZerodotJander posted:

Make sure you have relative references turned on.

"Use relative references" was activated by default.

Dead Pressed
Nov 11, 2009

ZerodotJander posted:

How are you selecting your range to sort during your macro record? Make sure whatever way you are doing that selects the full table and not just the range specified at the moment you record the macro.

You could also try just adding a sort column and numbering all your guests in order, and sorting based on that instead of a multi-field sort.

The range is selected via Control-A. Alternatively, clicking the top left button of the worksheet to select all has also been used. Neither method makes a difference.

Numbering every guest is out of the equation. We have hundreds of people, we want it in a certain order, and that'd be just too tedious by hand.

In reality, I can just show her how to sort it the way she wants (its only like 10 clicks of the mouse), and she can sort it herself when she adds new names to the list. I'm really just trying to figure this problem out, as I want a good handle on excel, and I have no idea why its not working. I figure if I can't get this simple macro like this to work, then I'm in trouble in the future.

I appreciate the help.

Dead Pressed
Nov 11, 2009

Sub Par posted:

Can you post the code? Excel isn't very good at recording a macro with the idea of a dynamic range, and oftentimes you will need to make a couple edits to what was recorded to make it work as you intended.

Certainly!
Now, I by no means coded this. Purely recorded the macro, so I have little to no idea what this means. This should be the last iteration of what I tried.

Excel posted:

Sub Mac2()

End Sub
Sub Sort()
'
' Sort Macro
'
' Keyboard Shortcut: Ctrl+Shift+S
'
Cells.Select
Range("K12").Activate
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("A2:A60") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("C2:C60") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("D2:D60") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("B2:B60") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Sheet1").Sort
.SetRange Range("A1:J60")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
E

EDIT: Obviously, it looks like for some reason its ending the sorting list at row 60. So I figure if I go in and edit that to 500 or so, it should accommodate up to number, correct?

EDIT2: Okay, looks like by changing all 60s to 500, it works exactly as intended. Does anyone have an idea as to why it would trim the range so low when I had selected all? Is there a way to prevent this in the future?

Thanks for the help!

Dead Pressed fucked around with this message at 07:25 on Jan 12, 2011

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply