Replace and Find VBA code for a command button

Patriot2879

Well-known Member
Joined
Feb 1, 2018
Messages
1,227
Office Version
  1. 2010
Platform
  1. Windows
Hi goodmorning all, hope you can help me place I have cells which sometimes has forexample -1, -4, -3 in them the range is cellsB24:P39, so what I do at the moment manually is CTRL F (find and replace) clickon replace tab – in find what enter (-*) and in replace with enter (0) thenreplace all.
What I wantto do is add a CommandButton1 to the sheet so I just have to click on it and itdoes this all for me to save a bit of time, is there a VBA code to do thisplease?
Hope youcan help please.

 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
You can use the macro recorder to get the code for something like that.
 
Upvote 0
Any problems just post the code you get & explain what's wrong.
 
Upvote 0
Thanks Fluff

I got it to work how I want :) I used he following code below.
Code:
Private Sub CommandButton1_Click()

    Range("B24:P39").Select
    Selection.Replace What:="*-*", Replacement:="0", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False
End Sub
 
Upvote 0
Glad you sorted it & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,094
Latest member
teemeren

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