Hello,
I have the code below and need to fill my ListBox with data from two sheets.
In sheet2 there are 21 columns;
In the sheet point is the columns H I J e Q
But every time I run it the MsgBox "Error!" appears, can someone tell me what I am doing wrong?
Sub Load_ListBox()
On Error GoTo Error
Dim SpreadsheetData As Worksheet
Set SheetData = ThisWorkbook.Worksheets("sheet2")
Dim SheetAppointment As Worksheet
Set WorksheetAppoint = ThisWorkbook.Worksheets("APPOINTMENT") '
Dim StartLine As Double
StartLine = 2
DimFinalRow As Double
EndRow = sheetData.UsedRange.rows.count
Dim columnStartColumn As Double
columnInitial = 1
Dim columnFinal As Double
columnFinal = 25
ListBox1.ColumnCount = 25
Dim arrayItems()
ReDim arrayItems(StartLine To EndLine, StartColumn To EndColumn)
Dim lineFilled As Double
FilledRow = StartRow
With SpreadsheetData
For row = StartRow To EndRow
Dim emptyRow As Boolean
EmptyRow = True
For column = columnStartTo columnFinal
If Not IsEmpty(.Cells(row, column).Value) Then
arrayItems(rowFilled, column) = .Cells(row, column).Value
emptyRow = False
End If
Next column
If Not emptyRow Then
lineFilled = lineFilled + 1
End If
Next row
End With
Fills the "HQIJ" column of the spreadsheet
Dim noteDataAttachment As Variant
AppointmentData = AppointmentSheet.Range("H2:Q" & EndLine).Value
For row = StartLine To EndLine
For column = 1 To 8
arrayItems(rowFilled, column + columnFinal) = dataAppointment(row, column)
Next column
Next Row
ReDim Preserve arrayItems(StartRow ToFilledRow - 1, StartColumn ToFinalColumn + 8)
ListBox1.List = arrayItems
Erase arrayItems
ListBox1.ColumnWidths = "40;33;100;65;35;30;40;40;30;30;26;45;32;30;30;30;30;30;30;30;30;50;40;50;40"
Exit Sub
Error:
MsgBox "Error!", vbCritical, "ERROR"
End Sub
Bookmarks