Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Sorting alphabetically across different sheets

Posted on 2011-02-25
9
Medium Priority
?
237 Views
Last Modified: 2012-05-11
I have 2 sheets. In Sheet1 names are entered in column A for use of the corresponding cell in Sheet2. In Sheet2 additional information is entered in column B. When adding or removing names from Sheet1 I would want to sort alphabetically. That's easy when sorting in Sheet2, but I would want to sort in Sheet1, but keeping column B in Sheet2 in the same row as the name it was entered with in column A.
Attached is a simple example before and after. Before is information entered, after is what I want it to look like by only sorting in Sheet1.

How do I do that
Before.xls
after.xls
0
Comment
Question by:Brasch
[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
9 Comments
 
LVL 4

Expert Comment

by:MarioAlcaide
ID: 34977994
Hello,

Maybe the following link will hjelp you, it's a similar case:

http://excel.bigresource.com/Track/excel-HucbZZMM/
0
 
LVL 5

Expert Comment

by:Kannan K
ID: 34978712

Hi,

You will have to write a macro to read the content from Sheet1 and write into sheet2 and do the sorting thru macro. as of now you are referring the sheet 1 cells in sheet 2 cell. sheet 2 will not know that, the sheet 1 has done sorting.

KK,
0
 

Author Comment

by:Brasch
ID: 34984761
@MarioAlcaide;
The formula in the link might work, but I simply do not completely understand what it does, so very hard to fit my needs

@Kannan;
problem is, that I have 35 sheets that I need to sort - I'd rather not have to sort all of them one after another. Anyway, what actions would that macro contain?

0
Independent Software Vendors: 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!

 
LVL 30

Accepted Solution

by:
SiddharthRout earned 2000 total points
ID: 34985317
Brasch: The problem is the formulas in column A of Sheet 2.

If there were not formulas then you could have used the code below to sort the entire range of sheets.

Sub SortAll()
    Dim LastRow As Long, lastCol As Long
    Dim ws As Worksheet
    
    For Each ws In ThisWorkbook.Sheets
        LastRow = ws.UsedRange.Rows.Count
        lastCol = ws.UsedRange.Columns.Count
        
        colname = Split(ws.Cells(, lastCol).Address, "$")(1)

        ws.Range("A2:" & colname & LastRow).Sort Key1:=ws.Range("A2"), _
        Order1:=xlAscending, Header:=xlGuess, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
        DataOption1:=xlSortTextAsNumbers
    Next
End Sub

Open in new window


Sid
0
 

Author Comment

by:Brasch
ID: 34985332
Well, the problem in example isn't (or shouldn't be) Sheet1 - it's basically a list of names - that could just as well be entered into sheet2, sheet1 is just for user-friendlyness, since the rest of the sheets also contain relevant data aside from the names. The problem arises in the "real world" when applying to the rest of my sheets. I somehow need to attach an entire row to the first cell in the row
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 34985347
If you have formulas referring to some other cell then sorting them will give you some undesired results. If only the 1st column in 2nd or the 3rd or any other sheet is connected to the 1st column of another sheet then it will create a problem.

Try and run the code that I gave and see what happens.

Sid
0
 

Author Comment

by:Brasch
ID: 34985363
It's getting quite late here, I'll give it a go after some sleep
0
 

Author Comment

by:Brasch
ID: 34987977
well, the code basically works the same way as the sort a-z, not much help. Considered putting all the sheets together in one "Enter Data" sheet, but since I'm using Office 2003 I'm running out of columns
0
 
LVL 30

Expert Comment

by:SiddharthRout
ID: 34991629
Brasch: Can I see the actual Excel File?

Sid
0

Featured Post

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!

Question has a verified solution.

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

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

609 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