Advertisement

There's no such thing as a stupid question, but they're the easiest to answer.
Login
Search

Advertisement

Business Applications Business Applications
Search Search
Search for:
Tech Support Guy > > >

Solved: How to execute a macro across a specific number of columns


(!)

lukasdylan's Avatar
lukasdylan lukasdylan is offline
Computer Specs
Member with 3 posts.
THREAD STARTER
 
Join Date: Jun 2012
Experience: Beginner
05-Jun-2012, 01:02 PM #1
Solved: How to execute a macro across a specific number of columns
Hello,

I am trying to learn rules in altering a macro that has been recorded. I need the following code to execute across columns A-AX, where each column is to be sorted independently of the others. Thank you in advance for your time.

Code:
    Range("A2:AX21").Select
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Sheet1").Sort.SortFields.Add Key:=Range("A2"), _
        SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Sheet1").Sort
        .SetRange Range("A2:A21")
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
End Sub
Keebellah's Avatar
Keebellah   (Hans) Keebellah is offline Keebellah is a Trusted Advisor with special permissions. Keebellah has a Profile Picture
Computer Specs
Trusted Advisor with 5,385 posts.
 
Join Date: Mar 2008
Location: Oegstgeest, The Netherlands
Experience: Advanced
05-Jun-2012, 04:54 PM #2
Hi, Welcome to the forum,
I did not entirely use your code.
Sheet1 contains code and I added a module with code that I use now thanks to Zack for retrieving column letters

I will sort columns A to AX independantly of each other.

I just used two columns to test, A and D
Attached Files
File Type: xlsm lukasdylan-Book1.xlsm (20.2 KB, 52 views)

Last edited by Keebellah; 05-Jun-2012 at 04:55 PM.. Reason: xtra infOooo
lukasdylan's Avatar
lukasdylan lukasdylan is offline
Computer Specs
Member with 3 posts.
THREAD STARTER
 
Join Date: Jun 2012
Experience: Beginner
05-Jun-2012, 07:21 PM #3
Hans:

Thank you for taking the time to share this with me. The macro works on your file, but when I try to run it on my file it asks me to create a new macro. (I copied the macro from your file into the VB Editor of my file.) Any thoughts as to what I'm doing wrong? Thanks again.
Keebellah's Avatar
Keebellah   (Hans) Keebellah is offline Keebellah is a Trusted Advisor with special permissions. Keebellah has a Profile Picture
Computer Specs
Trusted Advisor with 5,385 posts.
 
Join Date: Mar 2008
Location: Oegstgeest, The Netherlands
Experience: Advanced
06-Jun-2012, 01:36 AM #4
The macro either works, or doesn't work. It will never 'create' a new macro.
Could you explain more, where you put the code, did you also copy the GetcolumnModule to your file? etc.etc
lukasdylan's Avatar
lukasdylan lukasdylan is offline
Computer Specs
Member with 3 posts.
THREAD STARTER
 
Join Date: Jun 2012
Experience: Beginner
06-Jun-2012, 10:35 AM #5
I got it to work. It seemed to be an issue with file types. My data set was small, so I copied the whole thing into the file you created and everything worked great. Sorry for the confusion, but thanks again for helping me out with this.
Keebellah's Avatar
Keebellah   (Hans) Keebellah is offline Keebellah is a Trusted Advisor with special permissions. Keebellah has a Profile Picture
Computer Specs
Trusted Advisor with 5,385 posts.
 
Join Date: Mar 2008
Location: Oegstgeest, The Netherlands
Experience: Advanced
06-Jun-2012, 10:39 AM #6
No problem, happy coding
As Seen On

BBC, Reader's Digest, PC Magazine, Today Show, Money Magazine
WELCOME TO TECH SUPPORT GUY!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.


Tags
macro, vba code

(clock)
THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


WELCOME
You Are Using: Server ID
Trusted Website Back to the Top ↑