Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Using Wildcard in VBA IF

Thanks for any assistance you can provide. I have looked and can't seem to
find the answer and I don't think it should be that hard.

I have a column that has some text cells that start with "PO....". I would
like to replace all cells in that column with "" or delete the contents. I
thought just replacing with "" would be easiest. I have tried using * and ~
as wildcards. Neither is working

Here is what I was trying to use:

Range("a2:a98").Replace What:="P*", Replacement:=""
--
Thanks - K
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Using Wildcard in VBA IF

Sub kristen()
Set r = Range("A2:A98")
For Each rr In r
If Left(rr.Value, 2) = "PO" Then
rr.Value = ""
End If
Next
End Sub

--
Gary''s Student - gsnu200800
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Using Wildcard in VBA IF

I don't see anything wrong with the code, except maybe the sheet should be
specified. I tried it with different case just to be sure the Replace
function is not case sensitive and it worked regardless of case.

"Kristen" wrote:

Thanks for any assistance you can provide. I have looked and can't seem to
find the answer and I don't think it should be that hard.

I have a column that has some text cells that start with "PO....". I would
like to replace all cells in that column with "" or delete the contents. I
thought just replacing with "" would be easiest. I have tried using * and ~
as wildcards. Neither is working

Here is what I was trying to use:

Range("a2:a98").Replace What:="P*", Replacement:=""
--
Thanks - K

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using Wildcard in VBA IF

Yes, the posted statement worked for me also. I would note, though, that if
"PO" appeared anywhere in the text, then the PO and all text following it
gets deleted. For example, if the cell contains abcPOdef, then after
executing that line, the cell contains abc only.

Rick


"JLGWhiz" wrote in message
...
I don't see anything wrong with the code, except maybe the sheet should be
specified. I tried it with different case just to be sure the Replace
function is not case sensitive and it worked regardless of case.

"Kristen" wrote:

Thanks for any assistance you can provide. I have looked and can't seem
to
find the answer and I don't think it should be that hard.

I have a column that has some text cells that start with "PO....". I
would
like to replace all cells in that column with "" or delete the contents.
I
thought just replacing with "" would be easiest. I have tried using *
and ~
as wildcards. Neither is working

Here is what I was trying to use:

Range("a2:a98").Replace What:="P*", Replacement:=""
--
Thanks - K


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Using Wildcard in VBA IF

The only way I can replicate your problem is if the Text that ou describe is
there as the result of a formula. If it is a formula returning "PO..." then
you can not replace the value... Otherwise the code works for me...
--
HTH...

Jim Thomlinson


"Kristen" wrote:

Thanks for any assistance you can provide. I have looked and can't seem to
find the answer and I don't think it should be that hard.

I have a column that has some text cells that start with "PO....". I would
like to replace all cells in that column with "" or delete the contents. I
thought just replacing with "" would be easiest. I have tried using * and ~
as wildcards. Neither is working

Here is what I was trying to use:

Range("a2:a98").Replace What:="P*", Replacement:=""
--
Thanks - K



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using Wildcard in VBA IF

Just a quick note... this code is case sensitive and only works if the
leading PO is upper case whereas the code Kristen first posted would work no
matter what the PO's case was. I don't know if that matters to Kristen or
not, I just thought I would mention it. As for making the code case
insensitive (if that is what you want Kristen), chant the If..Then statement
in Gary''s Student's code to this...

If UCase(Left(rr.Value, 2) = "PO" Then

or to this...

If rr.Value Like "[Pp][Oo]*" Then

You can use either one as they both work the same.

Rick


"Gary''s Student" wrote in message
...
Sub kristen()
Set r = Range("A2:A98")
For Each rr In r
If Left(rr.Value, 2) = "PO" Then
rr.Value = ""
End If
Next
End Sub

--
Gary''s Student - gsnu200800


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default Using Wildcard in VBA IF

There is one other possibility that could cause the anomaly. If you have a
space before the data then it would not recognze the "P" as the first
character. So, try

Dim rng As Range
For Each rng In Range("A2:A98")
If UCase(LTrim(rng)) Like "P*" Then
rng = ""
End If
Next


"Kristen" wrote:

Thanks for any assistance you can provide. I have looked and can't seem to
find the answer and I don't think it should be that hard.

I have a column that has some text cells that start with "PO....". I would
like to replace all cells in that column with "" or delete the contents. I
thought just replacing with "" would be easiest. I have tried using * and ~
as wildcards. Neither is working

Here is what I was trying to use:

Range("a2:a98").Replace What:="P*", Replacement:=""
--
Thanks - K

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 30
Default Using Wildcard in VBA IF

This helped. Can you tell me if "rr" means anything particular?

I also continued to look and found that I could use "Like" and that seemed
to work.

If convertcell Like "P*" Then GoTo TextCell

I used like to just direct the program to skip over those cells. I have not
fully tested this, but I will do some more research.
--
Thanks - K


"Gary''s Student" wrote:

Sub kristen()
Set r = Range("A2:A98")
For Each rr In r
If Left(rr.Value, 2) = "PO" Then
rr.Value = ""
End If
Next
End Sub

--
Gary''s Student - gsnu200800

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Using Wildcard in VBA IF

rr is an individual cell in the range r.

Basically, we are looping over all the cells in the range and fixing them if
the criteria is met.
--
Gary''s Student - gsnu200800


"Kristen" wrote:

This helped. Can you tell me if "rr" means anything particular?

I also continued to look and found that I could use "Like" and that seemed
to work.

If convertcell Like "P*" Then GoTo TextCell

I used like to just direct the program to skip over those cells. I have not
fully tested this, but I will do some more research.
--
Thanks - K


"Gary''s Student" wrote:

Sub kristen()
Set r = Range("A2:A98")
For Each rr In r
If Left(rr.Value, 2) = "PO" Then
rr.Value = ""
End If
Next
End Sub

--
Gary''s Student - gsnu200800

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using the wildcard with IF DamienO New Users to Excel 5 January 29th 09 01:51 AM
If and wildcard Fish Excel Discussion (Misc queries) 3 October 1st 08 01:33 AM
Wildcard Robert[_30_] Excel Programming 1 May 18th 06 01:28 PM
Wildcard fugfug[_10_] Excel Programming 0 July 14th 05 12:34 PM
Wildcard kevin Excel Programming 3 May 25th 04 01:21 PM


All times are GMT +1. The time now is 11:10 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"