VBA ..... Direction change.....???

Tuckejam

Board Regular
Joined
Oct 15, 2013
Messages
81
Sorry I had no idea how to Title this post.

Im working with this wonderfull peice of VBA code that pulls (copys) all of the 9 digit values in a range and puts them into a column on the same worksheet.

Currently this runs in order of left to right, top to bottom. ie.. A1,A2,A3,B1,B2,B3

Is there any way to have it look top to bottom, then left to right? ie.. A1,B1,C1,A2,B2,C2.

Code:
Sub Solid()
Dim objReg   As Object, objMatch As Object, objColl  As Object
Dim rngWhole As Excel.Range
Dim rngCell  As Excel.Range
Dim lngRow   As Long: lngRow = 1
Set objReg = CreateObject("vbscript.regexp")
Set rngWhole = Sheets("Solid").Range("Solid")
With objReg
    .Global = True
    .Pattern = "\d{9}"
        For Each rngCell In rngWhole
            Set objColl = .Execute(rngCell.Value)
                For Each objMatch In objColl
                    Sheets("Solid").Range("cc" & lngRow).Value = objMatch.Value
                    lngRow = lngRow + 1
                Next objMatch
        Next rngCell
End With
Set objReg = Nothing
Set objMatch = Nothing
Set objColl = Nothing
Set rngWhole = Nothing
End Sub

Thanks for the help!
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
24,205
One way would be to explicity force it to

Code:
With RgnWhole
    For myR = 1 to .Rows.Count
        For myC = 1 to .Columns.Count
            Set rngCell = .Cells(myR, myC)
            ' your code
        Next myC
    Next myR
End With
 

NeonRedSharpie

Well-known Member
Joined
Jul 14, 2014
Messages
1,678
Code:
Sub Solid()

Dim arr As Variant 'This will hold the range values


Dim objReg   As Object, objMatch As Object, objColl  As Object
Dim rngWhole As Excel.Range
Dim rngCell  As Excel.Range
Dim lngRow   As Long: lngRow = 1
Set objReg = CreateObject("vbscript.regexp")
Set rngWhole = Sheets("Solid").Range("Solid")




With objReg
    .Global = True
    .Pattern = "\d{9}"
    
    arr = rngWhole  'Populate the array
    For y = 1 To UBound(arr, 2)
    For x = 1 To UBound(arr, 1)
        'For Each rngCell In rngWhole
            Set objColl = .Execute(arr(x, y))
                For Each objMatch In objColl
                    Sheets("Solid").Range("cc" & lngRow).Value = objMatch.Value
                    lngRow = lngRow + 1
                Next objMatch
        'Next rngCell
    Next x
    Next y
End With


End Sub

I think that should do it for you.
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,163,485
Messages
5,831,965
Members
430,098
Latest member
bemmelen

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
Top