CSV data to Array help

JumboCactuar

Well-known Member
Joined
Nov 16, 2016
Messages
785
Office Version
  1. 365
Platform
  1. Windows
Hi,
I have data in the following format and want to store the data of each order in an array but unsure how to code that

example data
i want a 2D array which stores the Item + QTY of each order
Item is unique on each order line

What i am attempting is to have a userform list all of the orders in one listbox, then when a row is clicked on it displays the order data

OrderNoItemQTY
G6RX6TVBCV54
1​
G6RX6TVBFV55
4​
G6RX6TVBCG55
1​
G6RX6TVBTG62
6​
G6RX6TVBRF22
7​
G6RX6TVBRT43
2​
G6RX6TVBTG62
1​
G6RX6TVBFR78
1​
G6RX6TVBDR44
5​
G6RX6TVBFV55
1​
F7TVF56FRT43
1​
F7TVF56FTG62
2​
F7TVF56FFD56
3​
F7TVF56FVF55
4​
F7TVF56FDR44
1​
F7TVF56FHN66
3​
F7TVF56FAC47
4​
F7TVF56FCG55
1​
F7TVF56FFH63
2​
F7TVF56FJH52
3​
C54FGBV6CG55
2​
C54FGBV6RF22
2​
C54FGBV6RT43
6​
C54FGBV6TG62
3​
C54FGBV6DR44
3​
C54FGBV6AC47
1​

appreciate any help
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
something like this:

AhbIYam.png
 
Upvote 0
Here's an example:
Note: data must be sorted by column A, if you want can add some lines in the the code to sort the data.
The workbook:

VBA Code:
Option Explicit
'NOTE: DATA MUST BE SORTED BY COLUMN A
Dim va
Dim d As Object

Private Sub UserForm_Initialize()
    Dim i As Long, j As Long
    With Sheets("Sheet1")  'change to suit
        va = .Range("A2", .Cells(.Rows.Count, "C").End(xlUp)) 'data in col A:C, start at row 2
    End With
    
    
    ListBox1.ColumnCount = 1
    ListBox2.ColumnCount = 2
    ListBox1.ColumnWidths = "150,30"
    
    Set d = CreateObject("scripting.dictionary"):    d.CompareMode = vbTextCompare

    For i = 1 To UBound(va, 1)
     j = i
        Do
            i = i + 1
            If i > UBound(va, 1) Then Exit Do
        Loop While va(i, 1) = va(i - 1, 1)
        i = i - 1
        d(va(i, 1)) = j & " : " & i
    Next
    ListBox1.List = d.keys
    
End Sub

Private Sub ListBox1_Change()
Dim z, vb, i As Long, k As Long
Dim tx As String

Application.StatusBar = ListBox1.ListIndex
tx = ListBox1.List(ListBox1.ListIndex, 0)

If d.Exists(tx) Then
    z = Split(d(tx), ":")
    ReDim vb(1 To (z(1) - z(0) + 1), 1 To 2)

    For i = z(0) To z(1)
        k = k + 1
        vb(k, 1) = va(i, 2)
        vb(k, 2) = va(i, 3)
    Next

End If

ListBox2.List = vb
End Sub
JumboCactuar.jpg
 
Upvote 0
Solution
Sorry, this line:
ListBox1.ColumnWidths = "150,30"
should be
ListBox2.ColumnWidths = "150,30"

Also we don't need this line:
Application.StatusBar = ListBox1.ListIndex
 
Upvote 0

Forum statistics

Threads
1,215,054
Messages
6,122,893
Members
449,097
Latest member
dbomb1414

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