Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default 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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default Look for a value and clear it

Excellent. Thanks Chip, I appreciate the explanation.

-- Dan

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
Transfer a name from one cell to another but leave clear if clear? Scoober Excel Worksheet Functions 3 May 22nd 09 02:55 AM
Why Doesn't it Clear?? Roger Excel Discussion (Misc queries) 5 January 30th 08 10:07 PM
clear the clear the web page email attachment lines MCrider Excel Discussion (Misc queries) 0 November 11th 07 10:05 PM
Not clear dkuz Excel Discussion (Misc queries) 4 February 14th 06 05:45 PM
Is there any way we cna clear everything.. shishi Excel Programming 1 August 10th 05 05:13 PM


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

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

About Us

"It's about Microsoft Excel"