VBA find and replace ?

mikeprice53

Active Member
Joined
Jan 21, 2003
Messages
297
I am trying to find text using vba method and replace with nothing to wipe out the value.

there are other things already in the cell so thats why I need to find and relace but I need to do it with a button hence hte VBA way !

Please help

Thanks
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Simply record a macro doing it manually. That will give you the code you need to place in your VBA code.
 
Upvote 0
good idea !

must ave been the 2 pints I had at lunch that is stopping me from thinking the easy method ! :0)

Like trying to stand up in a rowing boat huh !

Thanks :0)
 
Upvote 0
You mean like this?

Code:
Sub Macro5()
'
' Macro5 Macro
' Macro recorded 07/11/2003 by APoulsom
'

'
    Range("A1:A10").Select
    Selection.Replace What:="*a*", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False
End Sub

It looks for the letter a anywhere in the text and wipes out the whole cell.
 
Upvote 0
Thats excellent thank you once again Andrew ! I managed to change your code to fit mine in and it works awsomely ! :0)

Hope some day I can repay the favour or at elast pass on my little knowledge to help others. Ta ! ;)
 
Upvote 0
Dear Andrew, How do we manage same script specially replacement:"" to pick data from cell a11?
i have tried but its not working.
Code:
Selection.Replace What:="*a*", Replacement:="activecell.value="a11", LookAt:=xlPart, _         SearchOrder:=xlByRows, MatchCase:=False

can you help me in this regard?

Smith
</pre>
 
Upvote 0
Dear Andrew, How do we manage same script specially replacement:"" to pick data from cell a11?
i have tried but its not working.
Code:
Selection.Replace What:="*a*", Replacement:="activecell.value="a11", LookAt:=xlPart, _         SearchOrder:=xlByRows, MatchCase:=False

can you help me in this regard?

Smith

Code:
Selection.Replace What:="*a*", Replacement:=range("a11"),  LookAt:=xlPart, _         SearchOrder:=xlByRows, MatchCase:=False

Iknow it's pld post but it may help someone esle
 
Upvote 0
I realize this thread is pretty old, but my question may still apply.

I've been using that standard search and replace successfully, except when, just previously, I did a Ctrl-h from the Excel S&R (options>within) and selected workbook instead of sheet. After that, my vb script will fail. It attempts to also search and replace the whole workbook, over riding my selection. The script will only do the first row and quit. Not only does it do the first row, but it does columns outside of my selected range. I'd like to modify my script to clear whatever parameter is over riding my range selection.

You mean like this?

Code:
Sub Macro5()
'
' Macro5 Macro
' Macro recorded 07/11/2003 by APoulsom
'

'
    Range("A1:A10").Select
    Selection.Replace What:="*a*", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False
End Sub

It looks for the letter a anywhere in the text and wipes out the whole cell.
 
Upvote 0

Forum statistics

Threads
1,214,431
Messages
6,119,458
Members
448,899
Latest member
maplemeadows

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