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!
 

Some videos you may like

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
23,779
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.
 

Watch MrExcel Video

Forum statistics

Threads
1,108,910
Messages
5,525,583
Members
409,651
Latest member
Quasar Hunter

This Week's Hot Topics

Top