mismatch error when using sheets in array to populate data on userform

Mussala

Board Regular
Joined
Sep 28, 2022
Messages
87
Office Version
  1. 2019
Platform
  1. Windows
Hello ,
I try to populate data for all of sheets in listbox on userform , but shows mismatch error in this line
VBA Code:
r = Sheets(sh).Range("A1").CurrentRegion.Value


VBA Code:
Dim r As Variant


Sub LoadData()
Dim sh As Variant
For Each sh In Sheets(Array("Mussala", "mssau", "mjhgsg"))
r = Sheets(sh).Range("A1").CurrentRegion.Value
Next sh
 With Me.ListBox1
        .List = r
End With

End Sub
Private Sub UserForm_Initialize()
Call LoadData
  
End Sub
I hope some body fix this problem .
 
Rich (BB code):
    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
 
Upvote 0
Solution

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
perfect !
finally ,may you show headers in first row in listbox?
like
DATE, INVOICE NO, TYPE, DEBIT`, CREDIT, " BALANCE"
 
Upvote 0
Don't want to make it too complex and no benefit to experiencing such for me, so PLEASE ask someone else.
 
Upvote 0
Don't want to make ot too complex and no benefit to experiencing such for me, so PLEASE ask someone else.
my apologies!🙏🙏
I hope to getting assistance from you again to next thread with more clear details .;)
many thanks for your assistance.:)
 
Upvote 0

Forum statistics

Threads
1,225,626
Messages
6,186,094
Members
453,337
Latest member
fiaz ahmad

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