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
 
Re: commandbutton on click update textbox1 help

hi its 2016, shall I change it to click?
 
Upvote 0

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Re: commandbutton on click update textbox1 help

Well, the title you put on this thread is commandbutton on click.
 
Upvote 0
Re: commandbutton on click update textbox1 help

hi have changed it to click now please see code below but this comes up with a run time error 13 - type mismatch and the code is highlighted in yellow

Code:
Private Sub CommandButton5_Click()
TextBox1.Value = Sheets(Sheet5).Range("A1").Value
End Sub
 
Last edited:
Upvote 0
Re: commandbutton on click update textbox1 help

put the sheet name in double quotes
 
Upvote 0
Re: commandbutton on click update textbox1 help

great thank you that works :), thanks for your patience but I am pretty new to this :)
 
Upvote 0
Re: commandbutton on click update textbox1 help

No problem, we all had to start somewhere
 
Upvote 0
Re: commandbutton on click update textbox1 help

Thank you :), just one more quick query please :), in some cells that i want to copy across to the text box are onyl colour coded, for example cell in B2 is coloured in BLUE, but when i put the code in the colour doesn't copy over into the text box is this possible to do at all please? :) thanks again for everything
 
Upvote 0
Re: commandbutton on click update textbox1 help

Try this:
Code:
'Modified  10/5/2018  11:45:38 AM  EDT
TextBox1.Value = Sheets(3).Range("A1").Value
TextBox1.BackColor = Sheets(3).Range("A1").DisplayFormat.Interior.Color
 
Upvote 0
Re: commandbutton on click update textbox1 help

thank you very much this works great :)
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

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