View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default sorting 2 colums of numbers and incremening them down

If you use 11 columns (4 3 4), then what happens with those 3 columns in the
middle.

Are they left alone?

Do they travel with the first group of 4?

Do they travel with the last group of 4?



blk&wht wrote:

Dave,


Thank you for the sorting tip. I even have it sorting in the columns I want
and the number of columns associated with the sort but I can't get it to work
for the first 4
columns.

I have a 4 3 4 column sheet. The numbers are located in the 1st column and
the 8th column. Everything in columns 2-4 and 9-11 (which works with the
"myCols") shifts down.
I can't get columns 2-4 to shift with the result of column 1. Please see
sample. That's what the sheet look like. What do need to do to make columns
2,3 and 4 to shift down as well?

Thanks,

Bob

Cola Colh
614-53700-001 aa aa aa 614-53700-001 aa aa aa
615-20402-034 aa aa aa 615-20402-034 aa aa aa
615-20402-068 aa aa aa 615-20402-068 aa aa aa
615-20402-073 aa aa aa 615-20402-073 aa aa aa
615-20402-085 aa aa aa 615-20402-085 aa aa aa
615-20402-099 aa aa aa 615-20402-099 aa aa aa
615-20403-001 aa aa aa 615-20403-001 aa aa aa
615-20403-047 aa aa aa 615-20403-047 aa aa aa
615-20403-069 aa aa aa 615-20403-069 aa aa aa
615-20403-438 aa aa aa 615-20403-438 aa aa aa
615-20404-001 aa aa aa 615-20404-001 aa aa aa
615-20404-038 aa aa aa 615-20404-038 aa aa aa
615-20404-065 aa aa aa 615-20404-065 aa aa aa
615-20405-001 aa aa aa 615-20405-001 aa aa aa
615-20405-018 aa aa aa 615-20405-018 aa aa aa
615-20405-095 aa aa aa 615-20405-095 aa aa aa
615-20406-001 aa aa aa 615-20406-001 aa aa aa
615-20406-018 aa aa aa 615-20406-018 aa aa aa
615-20406-051 aa aa aa 615-20406-051 aa aa aa
615-20406-078 aa aa aa 615-20406-078 aa aa aa
615-60050-001 aa aa aa 615-20603-099 aa aa aa
621-62057-002 aa aa aa 621-62057-002 aa aa aa
624-10653-001 aa aa aa 624-10653-001 aa aa aa
628-54100-001 aa aa aa 628-54100-001 aa aa aa
630-10652-001 aa aa aa 630-10652-001 aa aa aa
630-10652-002 aa aa aa 630-10652-002 aa aa aa
630-10652-003 aa aa aa 630-10652-003 aa aa aa
630-52125-002 aa aa aa 630-53516-001 aa aa aa
632-10270-003 aa aa aa 632-10270-003 aa aa aa
632-10270-004 aa aa aa 632-10270-004 aa aa aa
632-10682-002 aa aa aa 632-10682-002 aa aa aa
634-10627-002 aa aa aa 634-10627-002 aa aa aa
637-10646-001 aa aa aa 637-10646-001 aa aa aa
637-10655-001 aa aa aa 637-10655-001 aa aa aa
640-10636-001 aa aa aa 640-10636-001 aa aa aa
640-10648-001 aa aa aa 640-10648-001 aa aa aa
640-10650-001 aa aa aa 640-10650-001 aa aa aa
640-10673-001 aa aa aa 640-10673-001 aa aa aa

"Dave Peterson" wrote:

Everything ends up in two columns, though, right?

Add a header to row 1 and try this macro that I've saved this from a few
previous posts:

Option Explicit
Sub testme()

Application.ScreenUpdating = False

Dim wks As Worksheet
Dim ColA As Range
Dim ColB As Range
Dim iRow As Long
Dim myCols As Long

Set wks = Worksheets("sheet1")
wks.DisplayPageBreaks = False
With wks
'row 1 has headers!
Set ColA = .Range("a2", .Cells(.Rows.Count, "A").End(xlUp))
Set ColB = .Range("b2", .Cells(.Rows.Count, "B").End(xlUp))

With ColA
.Sort key1:=.Cells(1), order1:=xlAscending, header:=xlNo
End With

'change the mycols to the number of columns that
'are associated with column B

myCols = 1 ' columns B only
With ColB.Resize(, myCols)
.Sort key1:=.Cells(1), order1:=xlAscending, header:=xlNo
End With

iRow = 2
Do
If Application.CountA(.Cells(iRow, "A").Resize(1, 2)) = 0 Then
Exit Do
End If

If .Cells(iRow, "A").Value = .Cells(iRow, "B").Value _
Or Application.CountA(.Cells(iRow, "A").Resize(1, 2)) = 1 Then
'do nothing
Else
If .Cells(iRow, "A").Value .Cells(iRow, "B").Value Then
.Cells(iRow, "A").Insert shift:=xlDown
Else
.Cells(iRow, "B").Resize(1, myCols).Insert shift:=xlDown
End If
End If
iRow = iRow + 1
Loop
End With

Application.ScreenUpdating = True

End Sub

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

blk&wht wrote:

If someone could help me with this that would be great if it's even posible.

I have 2 colums as shown below:

123 156
125 256
256 359
365 598
458 875
875 890
923 950

I would like to sort and increment the numbers down in order as shown below:

123
125
156
256 256
359
365
458
598
875 875
890
923
950

Like numbers would be on the same line, different number would be
numerically incremented in order in the colums they are in.

Thanks for help in advance
Bob

Email:



--

Dave Peterson


--

Dave Peterson