Two dimensional array with multi loop control

giri u

New Member
Joined
Jun 26, 2022
Messages
4
Office Version
  1. 2010
Platform
  1. Windows
I am try to run this code but its showing error

i want to run after first step of i loop go to next step of j loop

how to run this any one plz help me

Private Sub test()
Dim Col_List As Variant, To_List As Variant
Dim j As Long,i As Long

To_List = Array("Product Value", "Product Description", "UOM", "Mrp", "Value")
Col_List = Array("Product Value", "Product Description", "UOM", "[ ]", "Value")

For j = LBound(To_List) To UBound(To_List)
For i = LBound(Col_List) To UBound(Col_List)

Rest = To_List(j) & "/" & Col_List(i)

Next j
Next i

End Sub
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
I am not clear on what you want to achieve here, especially you don't seem to be doing anything with Rest.
The obvious things are:
• Rest is not dimmed
• Your For / Next pairs are out of Sync
You have "For j" first. This means the "Next j" should be last so that the For i & Next i are completely within j's For/Next

VBA Code:
Private Sub test()
    Dim Col_List As Variant, To_List As Variant
    Dim j As Long, i As Long
    Dim Rest As String
    
    To_List = Array("Product Value", "Product Description", "UOM", "Mrp", "Value")
    Col_List = Array("Product Value", "Product Description", "UOM", "[ ]", "Value")
    
    For j = LBound(To_List) To UBound(To_List)
        For i = LBound(Col_List) To UBound(Col_List)
            Rest = To_List(j) & "/" & Col_List(i)
            Debug.Print Rest
        Next i
    Next j

End Sub
 
Upvote 0
i need to run before go to Next i Next j
output like (To_List& "/" &Col_List) each one 1&1 2&2 3&3
 
Upvote 0
At the moment you are getting:
1&1,1&2,1&3.....2&1,2&2,2&3....

If both arrays have the same no of elements and you want a 1 for 1 match then just use 1 loop and use the same counter for both arrays eg

VBA Code:
Private Sub test()
    Dim Col_List As Variant, To_List As Variant
    Dim j As Long, i As Long
    Dim Rest As String
    
    To_List = Array("Product Value", "Product Description", "UOM", "Mrp", "Value")
    Col_List = Array("Product Value", "Product Description", "UOM", "[ ]", "Value")
    
    For j = LBound(To_List) To UBound(To_List)
            Rest = To_List(j) & "/" & Col_List(j)
            'Debug.Print Rest
    Next j

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,573
Messages
6,125,608
Members
449,238
Latest member
wcbyers

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