I think it would be helpful if you could provide a sample file...
Patrick
Main Topics
Browse All TopicsI am very new to vb coding for excel, but need to create a sorting system. I will try to be as specific as possible.
In worksheet 1, the range to sort is
Column 5, Row 15, to column 144, row 10,000 (some extremely high value to allow for future expansion of rows).
Every 10th column within this range belongs to a category. ie. Column 5, 15, 25, 35, etc... are together, Column 6, 16, 26, 36, etc... are together, and so on
In each field is either a number value or a blank.
So, working with the group that starts with column 5, I need to do the following for each row and output the data to worksheet 2:
- find out how many columns in the group for each row has some number value. So, if out of the entire group a row has values in only 2 of those columns, the output for that row would be "2" in a column in worksheet 2.
- sum the columns which do have a number value and output that sum in the next column. So, if one of the 2 columns is a "9" and the other is a "10", the output value would be 19 for that row.
I then need to sort these rows from greatest to least by the summed value column.
Then I need to move onto the next grouping of 10th columns, starting with column 6, doing the same thing, sorting by the summed values of each row.
When finished I should have groups of 2 columns for each of these 10th column categories, all sorted by the summed values.
I hope this makes sense!!!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Hi
http://www.d4ly.com/tourna
the macro that exists already is nothing malicious, just a program I wrote to make data entry easier :)
Thanks for taking the time to check it over
-D4
Here, I am writing code for Ladies_Fashion' only.
try similarly for other categories.
1)in sheet 2, at cell a3, type
=Sheet1!B15
2)in sheet 2, at cell b3, type
=Sheet1!C15
3)in sheet 2, at cell c3, type
=COUNT(Sheet1!E15)+COUNT(S
4)in sheet 2, at cell d3, type
=SUM(Sheet1!E15)+SUM(Sheet
5) copy the above four cell values to remaining rows.
6) for sorting use in a macro editor the following code,
Range("A3:D10000").Select
ActiveWorkbook.Names.Add Name:="Ladies_Fashion", RefersToR1C1:="=Sheet2!R3C
Selection.Copy
Selection.Sort Key1:=Range("D3"), Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
hope this helps,
from
SriRamIyer.
Hi D4,
You didn't mention it but I assumed that you would want to move the names over to Sheet2 also. This looks like it does what you wanted:
(Add this to Module1)
Sub SumSortTests()
Dim wb As Workbook, ws1 As Worksheet, ws2 As Worksheet
Dim rng As Range, cel As Range, ce As Range
Dim i As Long, j As Long, m As Long, n As Long
Application.ScreenUpdating
Set wb = ActiveWorkbook
Set ws1 = wb.Worksheets("Sheet1")
Set ws2 = wb.Worksheets("Sheet2")
Set rng = ws1.Range(ws1.Range("E15")
m = 3
For Each ce In Intersect(rng.Columns(1), rng)
For i = 1 To rng.Columns.Count Step 10
For j = 1 To 10
Set cel = rng.Cells(ce.Row - rng.Row + 1, (i - 1) + j)
If IsNumeric(cel) And cel <> "" Then
n = (j - 1) * 4 + 1
If Trim(ws2.Cells(m, n) & ws2.Cells(m, n + 1)) = "" Then
ws2.Cells(m, n) = ce.Offset(0, -3)
ws2.Cells(m, n + 1) = ce.Offset(0, -2)
End If
ws2.Cells(m, n + 2) = ws2.Cells(m, n + 2) + 1
ws2.Cells(m, n + 3) = ws2.Cells(m, n + 3) + cel.Value
End If
Next j
Next i
m = m + 1
Next ce
For i = 1 To 10
Set rng = Intersect(ws2.Range(ws2.Co
rng.Sort Key1:=rng.Cells(4), Order1:=xlDescending, _
Key2:=rng.Cells(3), Order2:=xlDescending, Header:=xlYes
Next i
Application.ScreenUpdating
End Sub
Jim
Wow Jim-
Thats even _more_ along the lines of what I'm looking for, and a lot easier to set up :)
Since both of you put the effort in I will split the points slightly in favor of jeverist. Let me know if either of you have a problem...
Jim, since I'm not just trying to copy and paste a solution I know nothing about into this thing,
Count Step 10
this is an incrementor by 10 instead of 1, moving to every 10th column, correct? Also, which part of the code grabs the first and last names? Thanks :)
If willing Jim, I would love to throw a bit of money your way for this. You've made my day.
- D4
Jim-
There is one issue with your code. I've assigned the sort to execute on a button click. When the button is pressed once, all the data is generated perfectly. After that however, any subsequent clicks does some other addition, re-ordering the rows, adding some value to each row (im not sure what exactly is happening). How can I fix it to do what the first click does every time?
D4,
> this is an incrementor by 10 instead of 1, moving to every 10th column, correct?
Yup.
> Also, which part of the code grabs the first and last names?
If Trim(ws2.Cells(m, n) & ws2.Cells(m, n + 1)) = "" Then
ws2.Cells(m, n) = ce.Offset(0, -3)
ws2.Cells(m, n + 1) = ce.Offset(0, -2)
End If
> any subsequent clicks does some other addition, re-ordering the rows...
If there's data already on Sheet2, executing the code again will add to that data and re-sort accordingly. We can re-initialize Sheet2 every time if you like by changing this:
Set ws2 = wb.Worksheets("Sheet2")
to:
Set ws2 = wb.Worksheets("Sheet2")
ws2.UsedRange.Offset(2).Cl
Jim
Business Accounts
Answer for Membership
by: sriramiyerPosted on 2006-03-09 at 20:02:43ID: 16151665
post your sample xls files here to try out
from
SriRamIyer.