Find * in a cell & ClearContents

  • Thread starter Thread starter Roger
  • Start date Start date
R

Roger

XL2000

I have a column of data, formatted as General, alpha numeric only, no
formulas. I want the macro to search each cell and when it finds one that
has an "*" just ClearContents of that cell or better yet replace the entire
contents of that cell with "No JS #". I can't get the following code to
work. Anybody have any better ideas?

Sub Replace()
For Each c In Range("n3:n100")
If (c.Value) Like "~*" Then c.ClearContents
Next c
End Sub

Examples of the column of data look like:
Col. N
----------
*D*0704
P1449F0
*D*0704
P1449F0
*D*0703
*D*0703


Thanks,

Roger
 
Roger,

Try it this way:

Sub Replace()
For Each c In Range("n3:n100")
If (c.Value) Like "[*]" Then c.ClearContents
Next c
End Sub
 
No luck, it just leaves the cells with an "*" alone like my other code.


Vergel Adriano said:
Roger,

Try it this way:

Sub Replace()
For Each c In Range("n3:n100")
If (c.Value) Like "[*]" Then c.ClearContents
Next c
End Sub





Roger said:
XL2000

I have a column of data, formatted as General, alpha numeric only, no
formulas. I want the macro to search each cell and when it finds one that
has an "*" just ClearContents of that cell or better yet replace the
entire
contents of that cell with "No JS #". I can't get the following code to
work. Anybody have any better ideas?

Sub Replace()
For Each c In Range("n3:n100")
If (c.Value) Like "~*" Then c.ClearContents
Next c
End Sub

Examples of the column of data look like:
Col. N
----------
*D*0704
P1449F0
*D*0704
P1449F0
*D*0703
*D*0703


Thanks,

Roger
 
Hmmn, the code I gave worked for me in XL2003, I didn't think there'd be a
difference in XL2000. A different approach would be this:

Sub Replace()
For Each c In Range("n3:n100")
If instr(1, c.Text, "*") > 0 Then c.ClearContents
Next c
End Sub


Roger said:
No luck, it just leaves the cells with an "*" alone like my other code.


Vergel Adriano said:
Roger,

Try it this way:

Sub Replace()
For Each c In Range("n3:n100")
If (c.Value) Like "[*]" Then c.ClearContents
Next c
End Sub





Roger said:
XL2000

I have a column of data, formatted as General, alpha numeric only, no
formulas. I want the macro to search each cell and when it finds one that
has an "*" just ClearContents of that cell or better yet replace the
entire
contents of that cell with "No JS #". I can't get the following code to
work. Anybody have any better ideas?

Sub Replace()
For Each c In Range("n3:n100")
If (c.Value) Like "~*" Then c.ClearContents
Next c
End Sub

Examples of the column of data look like:
Col. N
----------
*D*0704
P1449F0
*D*0704
P1449F0
*D*0703
*D*0703


Thanks,

Roger
 
another approach

If InStr(1, c, "*") > 0 Then c.ClearContents


--


Gary


Roger said:
No luck, it just leaves the cells with an "*" alone like my other code.


Vergel Adriano said:
Roger,

Try it this way:

Sub Replace()
For Each c In Range("n3:n100")
If (c.Value) Like "[*]" Then c.ClearContents
Next c
End Sub





Roger said:
XL2000

I have a column of data, formatted as General, alpha numeric only, no
formulas. I want the macro to search each cell and when it finds one that
has an "*" just ClearContents of that cell or better yet replace the entire
contents of that cell with "No JS #". I can't get the following code to
work. Anybody have any better ideas?

Sub Replace()
For Each c In Range("n3:n100")
If (c.Value) Like "~*" Then c.ClearContents
Next c
End Sub

Examples of the column of data look like:
Col. N
----------
*D*0704
P1449F0
*D*0704
P1449F0
*D*0703
*D*0703


Thanks,

Roger
 
Try something like this code which finds all cells in N3:N100 that contain an
asterisk and replaces their contents with "No JS #":

Sub AlterAsteriskCells()
Range("N3:N100").Replace _
What:="*~**", _
Replacement:="No JS #", _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
MatchCase:=False, _
SearchFormat:=False, _
ReplaceFormat:=False
End Sub

Is that something you can work with?
***********
Regards,
Ron

XL2002, WinXP


Roger said:
No luck, it just leaves the cells with an "*" alone like my other code.


Vergel Adriano said:
Roger,

Try it this way:

Sub Replace()
For Each c In Range("n3:n100")
If (c.Value) Like "[*]" Then c.ClearContents
Next c
End Sub





Roger said:
XL2000

I have a column of data, formatted as General, alpha numeric only, no
formulas. I want the macro to search each cell and when it finds one that
has an "*" just ClearContents of that cell or better yet replace the
entire
contents of that cell with "No JS #". I can't get the following code to
work. Anybody have any better ideas?

Sub Replace()
For Each c In Range("n3:n100")
If (c.Value) Like "~*" Then c.ClearContents
Next c
End Sub

Examples of the column of data look like:
Col. N
----------
*D*0704
P1449F0
*D*0704
P1449F0
*D*0703
*D*0703


Thanks,

Roger
 
Thanks, the last three of the recommendations worked exactly as I needed.

Thanks for the help, it is much appreciated, have a great day all.

Roger

Ron Coderre said:
Try something like this code which finds all cells in N3:N100 that contain
an
asterisk and replaces their contents with "No JS #":

Sub AlterAsteriskCells()
Range("N3:N100").Replace _
What:="*~**", _
Replacement:="No JS #", _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
MatchCase:=False, _
SearchFormat:=False, _
ReplaceFormat:=False
End Sub

Is that something you can work with?
***********
Regards,
Ron

XL2002, WinXP


Roger said:
No luck, it just leaves the cells with an "*" alone like my other code.


message
Roger,

Try it this way:

Sub Replace()
For Each c In Range("n3:n100")
If (c.Value) Like "[*]" Then c.ClearContents
Next c
End Sub





:

XL2000

I have a column of data, formatted as General, alpha numeric only, no
formulas. I want the macro to search each cell and when it finds one
that
has an "*" just ClearContents of that cell or better yet replace the
entire
contents of that cell with "No JS #". I can't get the following code
to
work. Anybody have any better ideas?

Sub Replace()
For Each c In Range("n3:n100")
If (c.Value) Like "~*" Then c.ClearContents
Next c
End Sub

Examples of the column of data look like:
Col. N
----------
*D*0704
P1449F0
*D*0704
P1449F0
*D*0703
*D*0703


Thanks,

Roger
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top