Ashgaroth

ashgaroth

New Member
Joined
Mar 10, 2010
Messages
18
I am trying to sort a spreadsheet by 2 columns and putting the names in a combo box in alphabetical order. Unfortunately, I keep getting a <subscript out of range? error.

This is the code that I am using and I have highlighted the line that is causing the error.

SortColumm1 = 0
SortColumn2 = 1
For i = LBound(ArrayName, 1) To UBound(ArrayName, 1) - 1
For j = LBound(ArrayName, 1) To UBound(ArrayName, 1) - 1
Condition1 = ArrayName(j, SortColumn1) > ArrayName(j + 1, SortColumn1)
Condition2 = ArrayName(j, SortColumn1) = ArrayName(j + 1, SortColumn1) And _
ArrayName(j, SortColumn2) > ArrayName(j + 1, SortColumn2)
If Condition1 Or Condition2 Then
For y = LBound(ArrayName, 2) To UBound(ArrayName, 2)
t = ArrayName(j, y)
ArrayName(j, y) = ArrayName(j + 1, y)
ArrayName(j + 1, y) = t
Next y
End If
Next
Next
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
I found the problem with this text.
The first line of the code reads Columm1=0 instead of Column1=0, so it works now.

Thanks Andrew for the link, this lokks good as it looks like it will help me with the sorting. The problem I have now is getting the names into the combox. At the moment it just shows surnames but where I have more than one person sharing the same surname I only get to see details for the first person. What I want to do is somehow concatenate the surname and first name details into the combo box.
 
Upvote 0

Forum statistics

Threads
1,214,614
Messages
6,120,525
Members
448,969
Latest member
mirek8991

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top