ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Look for a value and clear it (https://www.excelbanter.com/excel-programming/382845-look-value-clear.html)

Dan R.

Look for a value and clear it
 
I'm trying to find anything in column 9 that = "-//200-" and clear it.
Why does this not work?

iEnd = ws.Cells(65536, 9).End(xlUp).Row
Set rng = ws.Range(ws.Cells(3, 9), Cells(iEnd, 9))
For Each c In rng
If InStr(c, "-//200-") = False Then c.Clear
Next c

Thanks,
-- Dan


Dan R.

Look for a value and clear it
 
oops, that should be:

iEnd = ws.Cells(65536, 9).End(xlUp).Row
Set rng = ws.Range(ws.Cells(3, 9), Cells(iEnd, 9))
For Each c In rng
If InStr(c, "-//200-") = True Then c.Clear
Next c


Chip Pearson

Look for a value and clear it
 
Change

If InStr(c, "-//200-") = True Then c.Clear

to

If InStr(c, "-//200-") 0 Then c.Clear

True has a numeric value of -1, and InStr returns 0 or a positive integer
indicating the position at which the string was found. It will never
return -1. For example


Dim P As Integer
P = InStr(1, "ABC", "B")
Debug.Print "P = True: " & (P = True), "P = " & P


You'll see that P is not equal to True.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)



"Dan R." wrote in message
ups.com...
oops, that should be:

iEnd = ws.Cells(65536, 9).End(xlUp).Row
Set rng = ws.Range(ws.Cells(3, 9), Cells(iEnd, 9))
For Each c In rng
If InStr(c, "-//200-") = True Then c.Clear
Next c




Dan R.

Look for a value and clear it
 
Excellent. Thanks Chip, I appreciate the explanation.

-- Dan



All times are GMT +1. The time now is 01:01 PM.

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