Hello,
I'm not sure if it's possible to modifying code to make better when run the form .
the code will populate data in listbox across sheets on form excluding row contains OPENING word in column C and row contains TOTAL word in column A .
seem slight slow with simple data and with big data will be too slow .
so if there is alternitave code or adjusting original code to make better I truly appreciate for any help guys.
Private Sub UserForm_Initialize()
Call IMPORTDATA
End Sub
Sub IMPORTDATA()
Dim s$(1), x, e
For Each e In Array("Mussala", "mssau", "mjhgsg")
s(0) = s(0) & IIf(s(0) = "", "", "Union All (") & "Select " & _
"Format(`DATE`,'dd/mm/yyyy'), `INVOICE NO`, `TYPE`, `DEBIT`, `CREDIT`, " & _
"`BALANCE` From `" & e & "$` Where `TYPE` <> 'OPENING' And `TYPE` Is Not Null " & IIf(s(0) = "", "", ") ")
Next
s(1) = "Provider=Microsoft.Ace.OLEDB.12.0;Data Source=" & ThisWorkbook.FullName & _
";Extended Properties='Excel 12.0;HDR=Yes';"
With CreateObject("ADODB.Recordset")
.Open s(0), s(1), 3, 3, 1
x = .GetRows
End With
With Me.ListBox1
.ColumnCount = UBound(x, 1) + 1
.Column = x
For i = 0 To .ListCount - 1
.List(i, 3) = Format(.List(i, 3), "#,##0.00")
.List(i, 4) = Format(.List(i, 4), "#,##0.00")
Next i
End With
End Sub