Hello everyone
I am writing here because im in need of help when it comes to putting information from another workbook on the list box
The code below works but what is really screwing me over is the way that the information is being sent to the list box
In the image below you can see the values the listbox is being populated with
the main issue here is that the values from the second row are not under their respective columns (check the poorly drawn arrows to see where they should be)
Basically i need help to put the values from the second row right under their respective column
If anyone could help i would appreciate it,thanks for reading
I am writing here because im in need of help when it comes to putting information from another workbook on the list box
The code below works but what is really screwing me over is the way that the information is being sent to the list box
Code:
'----------------------------------------------------------List Box--------------------------------------------------------------------------
Sub UpdateListBoxAndSave()
Dim sourceWorkbook As Workbook
Dim sourceWorksheet As Worksheet
Dim sourceRange As Range
Dim listBox As MSForms.listBox
Dim dataArr As Variant
Dim i As Long, j As Long
Dim rowData As String
Application.DisplayAlerts = False
Set sourceWorkbook = Workbooks.Open("C:\Users\GCASTELO\Desktop\Teardown YF QR Code\dados.xlsm")
Set sourceWorksheet = sourceWorkbook.Worksheets("Dados")
Set sourceRange = sourceWorksheet.Range("B1:AA2")
Set listBox = ThisWorkbook.Sheets("Sheet1").OLEObjects("ListBox1").Object
listBox.Clear
dataArr = sourceRange.value
For i = 1 To 2
rowData = ""
For j = 1 To UBound(dataArr, 2)
Dim cellValue As String
cellValue = Trim(dataArr(i, j))
rowData = rowData & cellValue & vbTab
Next j
listBox.AddItem Trim(rowData)
Next i
sourceWorkbook.Save
sourceWorkbook.Close
' Re-enable display alerts
Application.DisplayAlerts = True
End Sub
'-----------------------------------------------------------------------------------------------------------------------------------------------------------
In the image below you can see the values the listbox is being populated with
the main issue here is that the values from the second row are not under their respective columns (check the poorly drawn arrows to see where they should be)
Basically i need help to put the values from the second row right under their respective column
If anyone could help i would appreciate it,thanks for reading