VBA User Form : Reference Value should come based on Button Click

sachinns

Board Regular
Joined
Jun 21, 2019
Messages
52
Hi Friends,

I have a VBA User Form consisting of 1 button and 2 textbox. When i press this button , the value of button is coming in the textbox1. Till this part i have completed.

Code:
Private Sub button1_Click()


If button1.Value = False Then
TextBox1.SelText = ComboBox1.Text + " "
Else
TextBox1.SelText = ComboBox1.Text + " " + TextBox1.Text + " "
End If
End Sub

I have one sheet where some values (value) are present. Corresponding to this values there are some other values (value2) .

So, when i press on the button , the value will goto textbox1 and this value (value) should be searched in the sheet and its corresponding value (value2) should come in the textbox2.

Can someone please help me on this.

Thanks
 
Last edited:
@@My Aswer Is This

Yeah I understood that you made the code very simpler. But i want this to work in the same way which i told. Because of so many reasons and client requirement.
I added my code and some changes that you need to help me. Please check my previous reply and help me on it.

Thanks
 
Upvote 0

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
I see now your overall objective is a lot more now.
I will be honest I'm not good at reading other peoples scripts and trying to see what the end result should be.

I like it when users says here is my end goal and let me write the script.

But there are a lot of other people on this forum that may be able to help you.

It appears what you wanting can be achieved by using my script.
Not sure why your now saying look at my script and modify it to my needs.


I will continue to monitor this thread to see what I can learn.
 
Upvote 0
@My Aswer Is This

Thanks a lot for spending time to help me. I cannot avoid the textbox1 as textbox1 will be visible to users while textbox2 is for back-end people. That is why i wanted my code to be edited.
You can see no one is responding to the thread. I will provide a small code where you can help me. So that i can implement on my code.


I have 2 buttons in my form. So when i press on Button1 , value "A" will come to textbox2 & textbox3 and when i press Button2 "B" will come in textbox2 & textbox3.
User can enter how much ever values to the textbox2 & textbox3 which will append to the last.
And also user can click on the textbox2 anywhere user wants , and can enter the values . ( I am using textbox2.Seltext instead of textbox2.text) .

Issue i am facing :

User pressed button1 2 times : Values in textbox2 and textbox3 will be " A A ".
Now the User pressed in between "A A" in the textbox. and then pressed button 2.
Values in textbox1 will be "A B A" while in textbox3 will be " A A B" . But i want the values in textbox3 same as textbox2 "A B A" .

Code:
Private Sub Button1_Click()


If TextBox2.SelText = "" Then
TextBox2.SelText = " A "
TextBox3.SelText = " A "
Else
TextBox2.SelText = TextBox2.SelText + " A "
TextBox3.SelText = TextBox3.SelText + " A "
End If


End Sub


Code:
Private Sub Button2_Click()


If TextBox2.SelText = "" Then
TextBox2.SelText = " B "
TextBox3.SelText = " B "
Else
TextBox2.SelText = TextBox2.SelText + " B "
TextBox3.SelText = TextBox3.SelText + " B "
End If


End Sub


Please Help me on this.
 
Upvote 0

Forum statistics

Threads
1,215,338
Messages
6,124,357
Members
449,155
Latest member
ravioli44

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