Value of a cell in a TextBox

Solved
Anonymous user -  
 Anonymous user -
Hello,

In Excel, I use a UserForm that has several TextBoxes.
In order for some of these TextBoxes to display the content of certain cells, when the UserForm opens, I use the following macro:

Private Sub UserForm_Initialize()

UserForm1.TextBox1.Value = Sheets(3).Cells(3, 1).Value
UserForm1.TextBox2.Value = Sheets(3).Cells(3, 2).Value
UserForm1.TextBox3.Value = Sheets(3).Cells(3, 3).Value
UserForm1.TextBox4.Value = Sheets(3).Cells(3, 4).Value

End Sub

I would like to insert a button in my UserForm that, when clicked, will display the values of the next cells in the same sheet (those from row 4).

Do you have any idea of the code I could use in this button to do that?

Thank you in advance

Laure

3 réponses

pijaku Posted messages 13513 Registration date   Status Modérateur Last intervention   2 771
 
Hello,
Try it like this:

 Dim var As Integer Private Sub CommandButton1_Click() var = var + 1 UserForm1.TextBox1.Value = Sheets(3).Cells(var, 1).Value UserForm1.TextBox2.Value = Sheets(3).Cells(var, 2).Value UserForm1.TextBox3.Value = Sheets(3).Cells(var, 3).Value UserForm1.TextBox4.Value = Sheets(3).Cells(var, 4).Value End Sub Private Sub UserForm_Initialize() var = 3 UserForm1.TextBox1.Value = Sheets(3).Cells(var, 1).Value UserForm1.TextBox2.Value = Sheets(3).Cells(var, 2).Value UserForm1.TextBox3.Value = Sheets(3).Cells(var, 3).Value UserForm1.TextBox4.Value = Sheets(3).Cells(var, 4).Value End Sub 

--
Best regards,
-- Every problem has its solution. If there is no solution, where is the problem? --
0
Anonymous user
 
Hello,

Thank you

It works except that it also displays the values for var = 1 and var = 2.

Laure
0
pijaku Posted messages 13513 Registration date   Status Modérateur Last intervention   2 771
 
How is that??? What exactly are you doing?
If when initializing your USF var has the value 3, it cannot give you the values for 1 and 2... Unless your USF is not initialized. How do you launch your USF? If it's by the command: UserForm1.Show, add the line Load UserForm1.
0
Anonymous user
 
Thank you, it works!
0