Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
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 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
I want to replace all "<br" with a new line character. | Excel Discussion (Misc queries) | |||
"Find" a wildcard as a place marker and "replace" with original va | Excel Discussion (Misc queries) | |||
match true exact "dd" vs. find next 5th character=y | Excel Discussion (Misc queries) | |||
How to replace "#N/A" w "0"when vlookup couldn't find the match? | Excel Discussion (Misc queries) | |||
Replace dialog should put focus on "Find What" not "Replace With" | Excel Discussion (Misc queries) |