?
Solved

Excel number sorting macro problem

Posted on 2013-02-04
7
Medium Priority
?
243 Views
Last Modified: 2013-02-13
I have this macro to sort numbers into ascending order left to right on multiple rows.

Im getting a runtime error.

Could it be fixed ?

Public Sub SortRows()

   Dim Row As Range
   For Each Row In Selection.Rows
      Row.Sort Key1:=Row.Cells(1, 1), Order1:=xlAscending, Header:=xlNo, Orientation:=xlLeftToRight
   Next Row

End Sub
0
Comment
Question by:Europa MacDonald
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 
LVL 49

Expert Comment

by:Martin Liss
ID: 38853150
Works fine for me. What error do you get and what does your rows look like?
0
 

Author Comment

by:Europa MacDonald
ID: 38853205
Run time error 1004

sort method of range class failed.

Im using 2003, could this be for a later version perhaps ?

columns A - F
random numbers in rows 1 - 80
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 38853248
All you probably need to do is to record a macro while you are doing what you want to do. If your range varies from time to time we can talk about that later.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Europa MacDonald
ID: 38853288
How do you record a macro ? (maybe thats another question?)
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 38853318
I don't have 2007 but here's an article that explains how.


Edit : Oops I see you use 2003. Be back soon.
0
 
LVL 49

Accepted Solution

by:
Martin Liss earned 2000 total points
ID: 38853327
Try this instead.
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 38885816
I'm glad I was able to help.

Marty - MVP 2009 to 2012
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question