Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

change showing data on form from sheet to multiple sheets

0

Hi

I want  populating data in combobox1,textbox1..... depends on  selected sheet from combobox2  instead of active sheet  .should populate item in combobox1  is relating with selected sheet from combobox2 also  textbox1,2,3 

currently the codes just depend on activesheet 

how could change that depends on selected sheet from combobox2,please?

Answer
Discuss

Answers

0
Selected Answer

Hi again Halk

Correction 06 April 2024

This doesn't rely on activating the selected sheet but clears and writes to the ComboBox list instead.

In the revised attached file, the code behind ComboBox2 shows how your code could be modified to change the ID control ComboBox1 :

Private Sub ComboBox2_Change()
    If Me.ComboBox2.Value = "" Then Exit Sub
    'clear existing list and entry
    ComboBox1.RowSource = ""
    ComboBox1.Text = ""
    With Worksheets(Me.ComboBox2.Value)
        'write new list
        Me.ComboBox1.List = Application.Transpose(.Range(.Range("B2"), .Range("B2").End(xlDown)))
    End With
End Sub

(Note: The user's sheets all had IDs with the prefix FLS but this is replaced by the second letter of the sheet name for illustration purposes e.g. sheet STW uses prefix TLS)

Revision 09 April 2024

In addition to illustration above, the attached file now brings back the required data. It does so by the simple addition in bold below when an ID in CombBox 2 is selected:

Private Sub ComboBox1_Change()
Dim c As Range


    Set c = Worksheets(Me.ComboBox2.Value).Range("B:B").Find(What:=ComboBox1.Value, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByRows, _
    SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
    If Not c Is Nothing Then
        TextBox1.Value = c.Offset(, 2).Text
        TextBox2.Value = c.Offset(, 3).Text
        TextBox3.Value = c.Offset(, 4).Text


    End If

End Sub

Hope this helps.

Discuss

Discussion

Hi John,
it's great !
but if I delete line .Activate then just works for active sheet
any way thank you .
Halk (rep: 30) Apr 5, '24 at 6:47 am
Halk. I'm mobile so can't test but it will work without Activate. Suggest you make unique codes per sheet (e.g FS.., JS... And WS..) then try. 
John_Ru (rep: 6142) Apr 5, '24 at 9:40 am
even if I change unique codes per sheet doesn't change anything.
just show for active sheet .
Halk (rep: 30) Apr 5, '24 at 12:37 pm
That's odd. Sorry but I'm quite remote for the whole weekend so can't check until Monday. 
John_Ru (rep: 6142) Apr 5, '24 at 2:11 pm
Halk- please see Correction 06 April 2024 to my Answer (and new file)
John_Ru (rep: 6142) Apr 7, '24 at 2:04 pm
does work for you ? !
still works for the active sheet !
Halk (rep: 30) Apr 9, '24 at 4:53 am
Halk. Yes it works for me....

If I download the file ...v0_b.xlsm from my Answer and launch it from the button (on worksheet STW), your UserForm_Initialize code puts TLSOO-.... references in the ID dropdown ComboBox2. If I then click the Sheet Names dropdown and pick sheet SMT,  the IDs now start MLSOO-...  (still on worksheet STW).
John_Ru (rep: 6142) Apr 9, '24 at 6:47 am
if I select SVT sheet will populate VLSOO... in combobox1 but when select specific ID will not show values in textboxes at all !
Halk (rep: 30) Apr 9, '24 at 8:40 am
Okay Halk but I only answered your question using an illustration (changing ComboBox2 to match ComboBox1 selection). I will revise my Answer/ file to extract the data too.
John_Ru (rep: 6142) Apr 9, '24 at 8:48 am
See Revision 09 April 2024 and revised file in my Answer.
John_Ru (rep: 6142) Apr 9, '24 at 8:52 am
Okay Halk but I only answered your question using an illustration (changing ComboBox2 to match ComboBox1 selection
sorry !
I thought the problem is from combobox2 !
now every thing is ok .
much appreciated for your time & help
Halk (rep: 30) Apr 9, '24 at 11:07 am
Great, glad that worked and thanks again for selecting my Answer, Halk. 
John_Ru (rep: 6142) Apr 9, '24 at 1:29 pm
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login