Sorting of an Array

quej2003

New Member
Joined
Oct 5, 2010
Messages
49
Hi All,

So I have an array, with a simplified look like so:

a b c d e
a b c d
a b c d e f


I was wondering if it is possible to basically "snap" everything to the right, so that the further right hand columns would have (decsendcing) e d f, second from right d c e, etc.
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
So you have a range several columns in width where you need to 'pad' the cells to the left in order to make the right hand columns flush?

Or is it the same, but applied to a vb 2 dimensional array?
 
Upvote 0
So you have a range several columns in width where you need to 'pad' the cells to the left in order to make the right hand columns flush?

Or is it the same, but applied to a vb 2 dimensional array?

Hmm I guess I wasn't very clear, and I confess to not quite understanding your language/terminology, so will try again!

I have a medium sized data set that is normally about 100-250 rows going downwards, then a variable number of columns. Essentially I have imported a text file then used the delimiter (using space), but all the information I am looking to use is in the final 7 columns of each row. Hm does this help?
 
Upvote 0
If the before/after is to be:
Excel Workbook
ABCDEF
1abcde
2abcd
3abcdef
4
5abcde
6abcd
7abcdef
Sheet4
Excel 2003

Maybe:
Rich (BB code):
Sub exa2()
Dim ary
Dim x As Long, y As Long, i As Long
    
    ary = Range("A1:F3")
    
    For x = UBound(ary, 1) To LBound(ary, 1) Step -1
        For y = UBound(ary, 2) To LBound(ary, 2) Step -1
            If ary(x, y) = Empty And Not y = LBound(ary, 2) Then
                i = y
                Do While Not i< LBound(ary, 2)
                    If ary(x, i) = Empty Then
                        i = i - 1
                    Else
                        ary(x, y) = ary(x, i)
                        ary(x, i) = Empty
                        Exit Do
                    End If
                Loop
            End If
        Next
    Next
    Range("A1:F3").Offset(4) = ary
    
End Sub
Probably a faster way, but is that in the right direction?
 
Upvote 0
Hi,
thanks, thats basically what I was looking for yes! seems to work perfectly for myself, much obliged (+ apologises for any misunderstanding!)
Cheers :)
 
Upvote 0
Cat-killin' curiousity has the best of me I am afraid. In response to Weaver's question, you said that you are only using the last seven columns (after padding right). What's happening with the rest of them, are you manually/thru code just deleting the columns?
 
Upvote 0
Cat-killin' curiousity has the best of me I am afraid. In response to Weaver's question, you said that you are only using the last seven columns (after padding right). What's happening with the rest of them, are you manually/thru code just deleting the columns?

In a few words, am deleting yes! chop chop
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,752
Members
452,940
Latest member
rootytrip

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