search in two worksheets with a form in vba

Asked

Viewed 52 times

-2

good afternoon people! my problem and the following: I have a form with 2 textbox one for students' names and another for the classroom and a spreadsheet with two tabs with the same names (txtNomeAlunos, txtSalaAlunosplan1-name, plan2-room) Would you like to know how to find this information in the 2 spreadsheets and bring it to my txts? from now on I thank you all

1 answer

0

Want to put the name of all the students in one Textbox? As if it were a Combobox? If you want a Combobox with the name of all students in a spreadsheet, do the following: Go to the spreadsheet and select the columns, or rows (depending on how you are) that your students' names are and right-click. Click "Define Name". Define a name, for example "Student Listings". In your Form, create a combobox (Combo box), change the name to cmbListaAlunos (or as you like, just for example here). Double-click the combo and edit this code:

Dim cLoc As Range
    Dim ws As Worksheet
    Set ws = Worksheets("NOME DA SUA PLANILHA")

For Each cLoc In ws.Range("O NOME QUE VOCÊ DEFINIU PARA A SELEÇÃO")
    With Me.cmbListaAlunos 
        .AddItem cLoc.Value
    End With
Next cLoc

This code will add all students of the spreadsheet in this combobox. To access another spreadsheet you need to activate it first. Sheets(WORKSHEET POSITION example: 1, 2 or 3). Activate.

Now, if with your system you want to show the students corresponding to a specific room, you can use this example to reflect. Because the code will be very complex to understand if it’s posted here.

If that answer wasn’t what you were looking for, just disregard.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.