View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 27,285
Default Macro to select cells within a range in which the cell color is none

that probably is because your interior is not a colorindex of zero (white)
but has not interior.colorindex (usually the default)

from the immediate window:
?xlNone
-4142

so with the code provided, if no cells are found, you can't do something
with -1 as the second argument to Left


Sub SelectWithBlancInterior()
Dim rngLoop As Range
Dim r as Ragne
'
For Each rngLoop In Range("A2", "A27")
If rngLoop.Interior.ColorIndex = xlNone Then
if r is nothing then
set r = rngLoop
else
set r = union(rngLoop,r)
end if
End If
Next
if not r is nothing then
r.Select
else
msgbox "None found"
end if
End Sub

concatenating a string with cell address is pretty constraining. Better to
use the union with a range reference.

--
Regards,
Tom Ogilvy



"PCLIVE" wrote in message
...
Thanks for the response

I tried this and I get a "Run-time error '5': Invalid procedure call or
argument" at:
strSubSet = Left(strSubSet, Len(strSubSet) - 1)

I pasted the code exactly with no other code involved. Am I missing
something?

Thanks,
Paul



"Executor" wrote in message
oups.com...
Hi Paul,

Try this:

Sub SelectWithBlancInterior()
Dim rngLoop As Range
Dim strSubSet As String
'
For Each rngLoop In Range("A2", "A27")
If rngLoop.Interior.ColorIndex = 0 Then
strSubSet = strSubSet & rngLoop.Address & ","
End If
Next
strSubSet = Left(strSubSet, Len(strSubSet) - 1)

Range(strSubSet).Select

End Sub


Hoop that helps,

Wouter