Google Answers Logo
View Question
 
Q: automate data sort in excel ( Answered 5 out of 5 stars,   0 Comments )
Question  
Subject: automate data sort in excel
Category: Computers > Software
Asked by: skooter867-ga
List Price: $50.00
Posted: 22 Apr 2006 05:02 PDT
Expires: 22 May 2006 05:02 PDT
Question ID: 721671
I have several sheets in Excel, which contain some ranges, where a
list of names can be entered along with associated columns of
statistics and comments. See example below. (FYI ? For my
record-keeping purposes, a blank cell with no data in it must be
distinguished from a cell that has had a zero put in it)

My goal is to have alphabetical master list automatically populated on
a separate tab. Up to now, I have been copying and pasting the ranges
to a separate sheet and then performing a data sort. Is there anyone
that can figure out how to automate this process? I have no knowledge
on how to use excel.

								
PUBLISHERS								
Name	Bks	Bro.	Hours	Mags	R.V.	B.S.	Comments
Cunningham, Kerry (Ovrsr)	 	 	 	 	 	 	 	 
Christie, Michael (Asst)	 	 	 	 	 	 	 	 
 	 	 	 	 	 	 	 	 
Cole, Jamin	 	 	 	 	 	 	 	 
Cunningham, Glen	 	 	 	 	 	 	 	 
Cunningham, S.	 	 	 	 	 	 	 	 
Garner, John	 	 	 	 	 	 	 	 
Garner, Lance	 	 	 	 	 	 	 	 
Garner, Peggy	 	 	 	 	 	 	 	 
Hudgins, Mike	 	 	 	 	 	 	 	 
Hudgins, Sue Ann	 	 	 	 	 	 	 	 
Hudgins, Steven	 	 	 	 	 	 	 	 
Hudgins, Micah	 	 	 	 	 	 	 	 
Morgan, David	 	 	 	 	 	 	 	 
Morgan, Vanessa	 	 	 	 	 	 	 	 
Lindsay, Amanda	 	 	 	 	 	 	 	 
Lindsay, James [2]	 	 	 	 	 	 	 	 
Morton, Michael A.	 	 	 	 	 	 	 	 
Slawinski, Deborah L.	 	 	 	 	 	 	 	 
Slawinski, Mike [1]	 	 	 	 	 	 	 	 
Stevenson, Cathy	 	 	 	 	 	 	 	 
 	 	 	 	 	 	 	 	 
 	 	 	 	 	 	 	 	 
 	 	 	 	 	 	 	 	 
 	 	 	 	 	 	 	 	 
 	 	 	 	 	 	 	 	 
 	 	 	 	 	 	 	 	 
Total	 	0	0	0	0	0	0	 
								
Please obtain any Late Reports from previous months
Name	Month	Bks	Bro.	Hours	Mags	R.V.	B.S.	Comments
Lindsay, James	Jan	 	 	 	 	 	 	 
Morgan, David	Mar	 	 	 	 	 	 	 
Morgan, Vanessa	Mar	 	 	 	 	 	 	 
Lindsay, James [2]	Mar	 	 	 	 	 	 	 
 	 	 	 	 	 	 	 	 
 	 	 	 	 	 	 	 	 
 	 	 	 	 	 	 	 	 
 	 	 	 	 	 	 	 	 
 	 	 	 	 	 	 	 	 
 	 	 	 	 	 	 	 	 
Total	 	0	0	0	0	0	0

Request for Question Clarification by hammer-ga on 22 Apr 2006 07:34 PDT
Skooter867,

This is doable, but we need more infomation. 
1. Which version of Excel do you use?
2. What ranges do you copy?
3. By which data do you sort?
4. Can you upload one of your spreadsheets to someplace where we can
see it, so we can test on your actual situation?

- Hammer

Clarification of Question by skooter867-ga on 26 Apr 2006 03:50 PDT
Sorry for not responding sooner. I didn't know that you had made a
reply. Thanks for figuring this out. I use Excel 2000. I've uploaded
the file to http://webpages.charter.net/skooter8675309/?N=D

The name of the file is "April 06 collection worksheet". You will
notice severals tabs, each one representing a different group, but the
ranges are the same in each tab. On the final tab, named "Alpha List",
is the place where I need to data from all the tabs to automatically
populate.

Let me know if you think this is possible. If you can do it, I will
need it by the end of the week. Thanks again
Answer  
Subject: Re: automate data sort in excel
Answered By: hammer-ga on 26 Apr 2006 06:13 PDT
Rated:5 out of 5 stars
 
Skooter867,

I added a button to your ALPHA LIST worksheet labelled Make Alpha
List. When you click it, Your Alpha List will populate from the other
nine worksheets, sort, total and format. The code behind the button is
pasted below. You can also see it by pressing Alt-F11 in your workbook
to open the code editor. Note that you may have to adjust your
security settings to allow the macro to run.

If you prefer, you can paste the macro into your own workbook(s) and
assign it to a button, hotkey or simply run it from the code editor.
If you do no, note that no line of code should wrap. The Answer box
may wrap lines. These will need to be unwrapped before the code will
run.

You can download the Excel file from here:
http://www.hammerdata.com/Google/CollectionWorksheetTemplate.xls

Please let me know if you have any questions.

Good luck with your Excel project!

- Hammer


' CODE BEGIN

Sub GetAlphaList()
Dim iLoop As Integer
Dim iLoopIn As Integer
Dim iCopy As Integer
Dim iRow As Integer
Dim iLastRow As Integer
Dim wks As Worksheet
Dim cwks As Worksheet
Dim rng As Range
Dim srng As Range

    iRow = 4
    Set wks = ThisWorkbook.Worksheets("ALPHA LIST")
    
    ' Do each of the nine individual worksheets
    For iLoop = 1 To 9
        Set cwks = ThisWorkbook.Worksheets(iLoop)
        
        ' Publishers section
        For iCopy = 5 To 31
            If Len(cwks.Cells(iCopy, 1).Value) > 0 Then
                For iLoopIn = 1 To 9
                    wks.Cells(iRow, iLoopIn).Value = cwks.Cells(iCopy,
iLoopIn).Value
                Next iLoopIn
                iRow = iRow + 1
            End If
        Next iCopy
        
        ' Late reports section
        For iCopy = 36 To 45
            If Len(cwks.Cells(iCopy, 1).Value) > 0 Then
                For iLoopIn = 1 To 9
                    wks.Cells(iRow, iLoopIn).Value = cwks.Cells(iCopy,
iLoopIn).Value
                Next iLoopIn
                iRow = iRow + 1
            End If
        Next iCopy
        
        ' Regular Pioneers section
        For iCopy = 56 To 59
            If Len(cwks.Cells(iCopy, 1).Value) > 0 Then
                For iLoopIn = 1 To 9
                    wks.Cells(iRow, iLoopIn).Value = cwks.Cells(iCopy,
iLoopIn).Value
                Next iLoopIn
                iRow = iRow + 1
            End If
        Next iCopy
        
        ' Auxiliary Pioneers section
        For iCopy = 66 To 73
            If Len(cwks.Cells(iCopy, 1).Value) > 0 Then
                For iLoopIn = 1 To 9
                    wks.Cells(iRow, iLoopIn).Value = cwks.Cells(iCopy,
iLoopIn).Value
                Next iLoopIn
                iRow = iRow + 1
            End If
        Next iCopy
    Next iLoop
    
    ' Sort data
    iLastRow = iRow - 1
    Set rng = wks.Range(Cells(4, 1), Cells(iLastRow, 9))
    Set srng = wks.Range(Cells(4, 1), Cells(iLastRow, 1))
    rng.Sort srng, xlAscending, , , , , , xlNo
    
    ' Total data
    wks.Cells(iRow, 1).Value = "TOTALS"
    For iLoop = 3 To 8
        Set srng = wks.Range(Cells(4, iLoop), Cells(iLastRow, iLoop))
        wks.Cells(iRow, iLoop).Value = Application.WorksheetFunction.Sum(srng)
    Next iLoop
    
    ' Format borders, alignment and fonts
    Set rng = wks.Range(Cells(4, 1), Cells(iRow, 9))
    rng.Borders.LineStyle = xlContinuous
    rng.Borders.Weight = xlThin
    rng.Range(Cells(4, 1), Cells(iRow, 1)).HorizontalAlignment = xlLeft
    rng.Range(Cells(4, 9), Cells(iRow, 9)).HorizontalAlignment = xlLeft
    rng.Range(Cells(4, 2), Cells(iRow, 8)).HorizontalAlignment = xlCenter
    rng.Font.Bold = False
    Set rng = wks.Range(Cells(iRow, 1), Cells(iRow, 9))
    rng.Font.Bold = True

    'Clean up
    Set wks = Nothing
    Set cwks = Nothing
    Set rng = Nothing
    Set srng = Nothing

End Sub

Request for Answer Clarification by skooter867-ga on 26 Apr 2006 08:50 PDT
Hi Hammer,

Wow! That was fast! The only thing I am now wondering is how the macro
can be made 'live', or be made to run in 'real-time', so that the
alpha list tab automatically reflects input and changes from the
sheets without having to click a button each time. Thanks again for
your support!

Clarification of Answer by hammer-ga on 26 Apr 2006 09:15 PDT
Skooter867,

Constant updating of a sorted accumulated list is a whole different
kettle of fish and a *much* more difficult one.

In your question, you said:
"Up to now, I have been copying and pasting the ranges to a separate
sheet and then performing a data sort. Is there anyone that can figure
out how to automate this process?"

So, I automated the process you described. It is meant to be run once
after you have filled out the rest of the spreadsheet. Otherwise, it
would be running and resorting continuously and would really slow you
down.

If you want, I can add to the macro so that it clears the existing
ALPHA LIST info before running. Then you can run it more than once per
workbook without having to manually clear out the existing Alpha List
data. I *can* also set it to run every time you change a cell, but I
don't think you'll be very happy with the results of doing so.

Let me know what you would like to do.

- Hammer

Request for Answer Clarification by skooter867-ga on 26 Apr 2006 09:37 PDT
Hammer,

I'm sorry for the confusion. As you described, perhaps you can make it
to clear out the existing data whenever it is updated. And if
possible, please set it to run every time a cell is changed. Once
again, thanks for your assistance.

Clarification of Answer by hammer-ga on 26 Apr 2006 10:47 PDT
Skooter867,

There are two versions of your Excel file available for you to
download. This one does as you asked and runs the Alpha List every
time you change anything on the nine individual sheets.
http://www.hammerdata.com/Google/CollectionWorksheetTemplateAutomatic.xls

If you decide that the performance hit from doing this is too much, I
updated the original file to clear the data so that you can click the
Make Alpha List button multiple times.
http://www.hammerdata.com/Google/CollectionWorksheetTemplate.xls

Please let me know if you need anything else.

- Hammer

Request for Answer Clarification by skooter867-ga on 26 Apr 2006 20:11 PDT
Hammer,

This is excellent work!! Thank you so much for your patience in
getting this right. I think I'm going to go with the automatic
version.

On a separate task, what would you charge to add a pie graph to this
spreadsheet? In particular, it would show the percentage of people in
all the ranges from all the sheets that have had either a zero or
higher number entered from the hour column only. This same pie chart
would appear to the right of the top table in each sheet. It would be
entitled "Congregation Overall" and depending on the amount of data
entered would say for example, "150 of 200 Reports Have Been
Submitted".

Of course, as names are added or deleted from the ranges, the chart
would need to reflect those values as well. If you could do this, that
would be the icing on the cake! Please let me know if you are
interested. Thanks again for everything!

Clarification of Answer by hammer-ga on 27 Apr 2006 04:56 PDT
<<    This is excellent work!! Thank you so much for your patience in
    getting this right. I think I'm going to go with the automatic
    version.
>>

I'm glad I was able to create a solution that worked for you.

<<    On a separate task, what would you charge to add a pie graph to this
    spreadsheet? ... Please let me know if you are interested. Thanks
again         for everything!
>>

It sounds interesting, but I can't guarantee I'll get to it within
your time frame. Why don't you post it as a separate question? Make
the final version of the spreadsheet available to the Researchers, as
you did with your original. I'll pick it up if I can. If not, I'm not
the only Researcher who answers Excel questions. By posting it
separately, you increase the number of people who can work on it. One
of us will likely get it done for you.

Again, I'm glad it's working for you!

- Hammer
skooter867-ga rated this answer:5 out of 5 stars

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy