|
-
Aug 30th, 2005, 02:33 PM
#1
Thread Starter
New Member
Newbie Question - help with code
Hi All,
I'm REALLY new to visual basic. I'm creating a macro that will sort data on a large excel spreadsheet. The data is constantly changing (the number of rows change... number of columns is fixed). The sort will always be starting from the same point (row 12).
What code will work for this? Will a Do Loop work? How do I write the code so that it will select all rows until there is no more data?
Thanks so much for the help!
-
Aug 30th, 2005, 02:41 PM
#2
Re: Newbie Question - help with code
Welcome to the Forums.
Something like this...
VB Code:
Range("A12:G12").Sort Key1:=Range("A12"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Aug 30th, 2005, 05:13 PM
#3
Re: Newbie Question - help with code
Hi,
In fat, you could select all the data - "A12:IV65536" and put in enough keys to sort one column after another. Key1, as RobDog shows, is the first sort key, but you can add more. So, for example, you could sort by column A and where items in column A are the same, sort by column C and so on. Or by row, it doesn't matter.
Not entirely sure what you mean by "Select all rows until there is no more data..." unless you mean that you are sorting by row instead of by column and you want to do all of them, in which case what I have said about selecting all the data and setting the appropriate paramter to sort by row will be sufficient.
The Office VBA Help on the Sort method is pretty clear, and tells you all the possible options for the various parameters.
HTH
zaza
-
Aug 30th, 2005, 05:27 PM
#4
Thread Starter
New Member
Re: Newbie Question - help with code
Thanks for the speedy replies!
I'm looking to select all rows with data starting with Row 12 (to be sorted later). So I wanted to select all rows until it hit a blank row. This is a large report where the number of rows changes (columns are fixed), so the code needs to take that into consideration.
From there I would sort whatever I needed... I wasn't as concerned with the sort part as I was with the Selection part.
Thanks again!!!
-
Aug 31st, 2005, 08:10 AM
#5
Lively Member
Re: Newbie Question - help with code
Rob's Code will do your sort without need for selection. If you need the rows to actually be selected for another reason, this will do it:
VB Code:
Range("A12:G" & Range("A12").End(xlDown).Row).Select
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|