Find Button

FlashGordy

New Member
Joined
Mar 23, 2011
Messages
8
Afternoon again guys.

I was wondering how one would go about adding a button into a a sheet which, when clicked would find and replace a specific character or value, on another sheet, without requiring confirmation.

Thanks
Gordon
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

JamesW

Well-known Member
Joined
Oct 30, 2009
Messages
1,197
Hi there,

Add your button using the Control Toolbox, double click on it and paste this in:

Code:
Private Sub CommandButton1_Click()
    lRow = Sheets("[U][B]Sheet2[/B][/U]").Range("[U][B]A1[/B][/U]").End(xlDown).Row
    Sheets("[B][U]Sheet2[/U][/B]").Range("[U][B]A1:A[/B][/U]" & lRow).Replace What:="[U][B]b[/B][/U]", Replacement:="[U][B]s[/B][/U]"
End Sub

Change the bold and underlined bits to whatever you wish.
 

FlashGordy

New Member
Joined
Mar 23, 2011
Messages
8
Hi James

I'm using Excel for Mac. So I'm guessing I right click on the button I created and go to "Assign Macro"? It creates a Macro called "Button1_Click" but will not let me paste anything underneath?

Gordon
 

JamesW

Well-known Member
Joined
Oct 30, 2009
Messages
1,197
Ah, erm... Not sure about Mac unfortunatly.

Try adding this to the module, instead of the click event:

Code:
Sub stuff()
    lRow = Sheets("Sheet2").Range("A1").End(xlDown).Row
    Sheets("Sheet2").Range("A1:A" & lRow).Replace What:="b", Replacement:="s"
End Sub
and then assigning the button to 'stuff' - Change the name if you like.
 

FlashGordy

New Member
Joined
Mar 23, 2011
Messages
8

ADVERTISEMENT

I've tried it on a windows machine too, and I'm still unable to edit the macro. I'm kinda new to the whole macro thing, so don't know if I'm just doing something stupid.

How does one "add to the module" and "assign a button"?
 

GK039

Board Regular
Joined
Oct 29, 2010
Messages
220

ADVERTISEMENT

Alt + F11 to open the VB Editor. Go Insert --> Module and then paste the code provided from James

George

I've tried it on a windows machine too, and I'm still unable to edit the macro. I'm kinda new to the whole macro thing, so don't know if I'm just doing something stupid.

How does one "add to the module" and "assign a button"?
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,167,651
Messages
5,854,954
Members
431,689
Latest member
jacker01

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
Top