ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Find and replace "?" character (https://www.excelbanter.com/excel-programming/396178-find-replace-character.html)

Zoltan

Find and replace "?" character
 
Hello,

I have an easy question which I could solve so far.
I would like to find all ? character on a worksheet and delete it from each
cells.

My code is:

Private Sub CommandButton2_Click()
Dim rng1 As Range
Dim mycell1 As Range
Set rng1 = Range("h98:i100")
For Each mycell1 In rng1

If Not mycell1.Find("?") Is Nothing Then
mycell1.Replace What:="?", replacement:=""
End If
Next

End Sub


the result is, that it deletes each character, not just the ?s. My idea is,
that this is because ? is a special character to be used to look for
something which is not known in an expression.

How can I replace my ?s ? And onyl the ?s ?

Thanks for your help,
Zoltan

Michael

Find and replace "?" character
 
Enclose the ? in brackets:
Private Sub CommandButton2_Click()
Dim rng1 As Range
Dim mycell1 As Range
Set rng1 = Range("h98:i100")
For Each mycell1 In rng1

If Not mycell1.Find([?]) Is Nothing Then
mycell1.Replace What:=[], replacement:=""
End If
Next
End Sub

Et

--
If this posting was helpful, please click on the Yes button.
Regards,

Michael Arch.




"Zoltan" wrote:

Hello,

I have an easy question which I could solve so far.
I would like to find all ? character on a worksheet and delete it from each
cells.

My code is:

Private Sub CommandButton2_Click()
Dim rng1 As Range
Dim mycell1 As Range
Set rng1 = Range("h98:i100")
For Each mycell1 In rng1

If Not mycell1.Find("?") Is Nothing Then
mycell1.Replace What:="?", replacement:=""
End If
Next

End Sub


the result is, that it deletes each character, not just the ?s. My idea is,
that this is because ? is a special character to be used to look for
something which is not known in an expression.

How can I replace my ?s ? And onyl the ?s ?

Thanks for your help,
Zoltan


Vergel Adriano

Find and replace "?" character
 
Put a tilde (~) character before the ?. You can also don't need to loop.

Range("h98:i100").Replace What:="~?", Replacement:=""


--
Hope that helps.

Vergel Adriano


"Zoltan" wrote:

Hello,

I have an easy question which I could solve so far.
I would like to find all ? character on a worksheet and delete it from each
cells.

My code is:

Private Sub CommandButton2_Click()
Dim rng1 As Range
Dim mycell1 As Range
Set rng1 = Range("h98:i100")
For Each mycell1 In rng1

If Not mycell1.Find("?") Is Nothing Then
mycell1.Replace What:="?", replacement:=""
End If
Next

End Sub


the result is, that it deletes each character, not just the ?s. My idea is,
that this is because ? is a special character to be used to look for
something which is not known in an expression.

How can I replace my ?s ? And onyl the ?s ?

Thanks for your help,
Zoltan


Don[_30_]

Find and replace "?" character
 
On Aug 23, 10:24 am, Michael
wrote:
Enclose the ? in brackets:
Private Sub CommandButton2_Click()
Dim rng1 As Range
Dim mycell1 As Range
Set rng1 = Range("h98:i100")
For Each mycell1 In rng1

If Not mycell1.Find([?]) Is Nothing Then
mycell1.Replace What:=[], replacement:=""
End If
Next
End Sub

Et

--
If this posting was helpful, please click on the Yes button.
Regards,

Michael Arch.



"Zoltan" wrote:
Hello,


I have an easy question which I could solve so far.
I would like to find all ? character on a worksheet and delete it from each
cells.


My code is:


Private Sub CommandButton2_Click()
Dim rng1 As Range
Dim mycell1 As Range
Set rng1 = Range("h98:i100")
For Each mycell1 In rng1


If Not mycell1.Find("?") Is Nothing Then
mycell1.Replace What:="?", replacement:=""
End If
Next


End Sub


the result is, that it deletes each character, not just the ?s. My idea is,
that this is because ? is a special character to be used to look for
something which is not known in an expression.


How can I replace my ?s ? And onyl the ?s ?


Thanks for your help,
Zoltan- Hide quoted text -


- Show quoted text -


To search for a character that is also a wildcard within a text
string, precede it with a tilde ~. That will specify the character,
not the wildcard, as the search criteria. Same thing works for find
and find/replace.


Zoltan

Find and replace "?" character
 
Thanks for the helps. You solved my problem. Tilde works.

Zoltan

"Vergel Adriano" wrote:

Put a tilde (~) character before the ?. You can also don't need to loop.

Range("h98:i100").Replace What:="~?", Replacement:=""


--
Hope that helps.

Vergel Adriano


"Zoltan" wrote:

Hello,

I have an easy question which I could solve so far.
I would like to find all ? character on a worksheet and delete it from each
cells.

My code is:

Private Sub CommandButton2_Click()
Dim rng1 As Range
Dim mycell1 As Range
Set rng1 = Range("h98:i100")
For Each mycell1 In rng1

If Not mycell1.Find("?") Is Nothing Then
mycell1.Replace What:="?", replacement:=""
End If
Next

End Sub


the result is, that it deletes each character, not just the ?s. My idea is,
that this is because ? is a special character to be used to look for
something which is not known in an expression.

How can I replace my ?s ? And onyl the ?s ?

Thanks for your help,
Zoltan



All times are GMT +1. The time now is 12:04 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com