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
Solved

Sorting alphabetically across different sheets

Posted on 2011-02-25
9
233 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
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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 30

Accepted Solution

by:
SiddharthRout earned 500 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

856 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