commandbutton on click update textbox1

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,259
Office Version
  1. 2010
Platform
  1. Windows
Hi hope you can help me please, I have the following code below, where when command button is clicked on I want it to auto update textbox1 with the data it finds in sheet 5, Colum A and row 1, can you help me please?
Code:
Private Sub CommandButton5_AfterUpdate()
   Dim Fnd As Range
   
   Set Fnd = Sheets("Sheet5").Range("A:A").Find(CommandButton5.Value, , , xlWhole, , , False, , False)
   If Not Fnd Is Nothing Then
      TextBox1.Value = Fnd.Offset(, 1).Value
   End If
   
End Sub
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Re: commandbutton on click update textbox1 help

HI sorry forgot to mention I have a userform as well, the button in their is called commandbutton5 and when that is clicked on I want the textbox1 to autofill with data in A1 on Sheet5 hope this makes sense, the code above was what I used for a drop down box but it doesn't work for my button hope you can help me please?
 
Upvote 0
Re: commandbutton on click update textbox1 help

Try this:
TextBox1.value=Sheets(5).Range("A1").value
 
Upvote 0
Re: commandbutton on click update textbox1 help

hi I have changed it to the below but still nothing. please see the updated code below, and thanks for your reply, hope you can still help me.
Code:
Private Sub CommandButton5_AfterUpdate()
   Dim Fnd As Range
   
   Set Fnd = Sheets("Sheet5").Range("A:A").Find(CommandButton5.Value, , , xlWhole, , , False, , False)
   If Not Fnd Is Nothing Then
      TextBox1.Value = Sheets(5).Range("A1").Value

   End If
   
End Sub
 
Upvote 0
Re: commandbutton on click update textbox1 help

Please explain in words what you trying to do.
It looks like your searching Column A for the value in command button five value.

Well a Command Button does not have a value
And if something is not found then enter Sheet(5).Range("A1"). value

What are you trying to find in column A

You have this:
Find(CommandButton5.Value
 
Last edited:
Upvote 0
Re: commandbutton on click update textbox1 help

hi what I want is to copy what is in A1 into textbox1 on the click of the command button
 
Upvote 0
Re: commandbutton on click update textbox1 help

I hope you can help :) I am still pretty new to all this :) thank you
 
Upvote 0
Re: commandbutton on click update textbox1 help

I gave you a answer:

TextBox1.Value = Sheets(5).Range("A1").Value

So why are you using all this find script?

And your original script said Sheet 5

So on what sheet is this value you want.
Change Sheet5 to what ever sheet.
 
Last edited:
Upvote 0
Re: commandbutton on click update textbox1 help

Hi thanks for the reply, I have just changed it to the following but it still doesn't copy across
Code:
Private Sub CommandButton5_AfterUpdate()
TextBox1.Value = Sheets(Sheet5).Range("A1").Value
   
End Sub
 
Upvote 0
Re: commandbutton on click update textbox1 help

What version of Excel are you using ?
I have 2010 and Command Buttons don't have an _AfterUpdate event.
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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