PC Review


Reply
Thread Tools Rate Thread

checking a range for at least one

 
 
Theo
Guest
Posts: n/a
 
      24th Jan 2008
I have code that will hi-light a cell if it is empty based on input in the
first cell:

For Each cll In Range("A:A")
If cll.Value = "A" Or cll.Value = "a" Then
If IsEmpty(cll.Offset(0, 1)) Then cll.Offset(0, 1).Interior.ColorIndex = 6 _
Else: cll.Offset(0, 1).Interior.ColorIndex = xlNone
End If

Now I still need to do:
For Each cll In Range("A:A")
If cll.Value = "A" Or cll.Value = "a" Then

but now I need to check to see if a range of cells are all null (at least
one of them
must NOT be null)

For example - if R:V and X are empty, then I want to hi-light R:V and X to
show that at least one of them must have data.

Any help is MUCH appreciated.

 
Reply With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      24th Jan 2008
First, read this from VBA help.

IsEmpty only returns meaningful information for variants.

This suggestion is based on what you described.
myRange = Range(ToBeDefined)
If cll.Offset(0, 1) = "" Then
cll.Offset(0, 1).Interior.ColorIndex = 6
For Each c In myRange 'myRange must be defined
If Not c Is Nothing Then
MsgBox "Data Here " & c.Address
End If
Next
End If
"Theo" wrote:

> I have code that will hi-light a cell if it is empty based on input in the
> first cell:
>
> For Each cll In Range("A:A")
> If cll.Value = "A" Or cll.Value = "a" Then
> If IsEmpty(cll.Offset(0, 1)) Then cll.Offset(0, 1).Interior.ColorIndex = 6 _
> Else: cll.Offset(0, 1).Interior.ColorIndex = xlNone
> End If
>
> Now I still need to do:
> For Each cll In Range("A:A")
> If cll.Value = "A" Or cll.Value = "a" Then
>
> but now I need to check to see if a range of cells are all null (at least
> one of them
> must NOT be null)
>
> For example - if R:V and X are empty, then I want to hi-light R:V and X to
> show that at least one of them must have data.
>
> Any help is MUCH appreciated.
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      24th Jan 2008
You may find applying Format|conditional formatting easier (and quicker to
implement).

But...

dim cll as range
with ActiveSheet
for each cll in .range("a:a").cells
if lcase(cll.value) = "a" then
if isempty(cll.offset(0,1).value) then
cll.offset(0,1).interior.colorindex = 6
else
cll.offset(0,1).interior.colorindex = xlnone
end if

if application.counta(.cells(cll.row,"R").resize(1,5)) = 0 _
and isempty(.cells(cll.row,"X").value) then
'all cells empty
'do your formatting
.cells(cll.row,"R").resize(1,5)).interior.colorindex = 6
.cells(cll.row,"X").interior.colorindex = 6
else
.cells(cll.row,"r").resize(1,5).interiorcolorindex = xlnone
.cells(cll.row,"X").interior.colorindex = xlnone
end if
end if
next cll
end with

(untested, uncompiled. watch for typos)

You may want to limit yourself to the range to check.

Maybe...
with ActiveSheet
for each cll in .range("a1", .cells(.rows.count,"A").end(xlup)).cells
....


Theo wrote:
>
> I have code that will hi-light a cell if it is empty based on input in the
> first cell:
>
> For Each cll In Range("A:A")
> If cll.Value = "A" Or cll.Value = "a" Then
> If IsEmpty(cll.Offset(0, 1)) Then cll.Offset(0, 1).Interior.ColorIndex = 6 _
> Else: cll.Offset(0, 1).Interior.ColorIndex = xlNone
> End If
>
> Now I still need to do:
> For Each cll In Range("A:A")
> If cll.Value = "A" Or cll.Value = "a" Then
>
> but now I need to check to see if a range of cells are all null (at least
> one of them
> must NOT be null)
>
> For example - if R:V and X are empty, then I want to hi-light R:V and X to
> show that at least one of them must have data.
>
> Any help is MUCH appreciated.


--

Dave Peterson
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Checking a range with IF =?Utf-8?B?Um9iIEo=?= Microsoft Excel Misc 4 18th Oct 2006 05:44 PM
Checking range of cells for entry then checking for total =?Utf-8?B?QmFyYiBSZWluaGFyZHQ=?= Microsoft Excel Programming 1 13th Oct 2006 02:47 PM
Checking if a cell value in one range is contained in a second range? ModelerGirl Microsoft Excel Discussion 4 21st Feb 2006 03:16 PM
range checking kev carter Microsoft Excel Misc 2 8th Apr 2004 07:27 PM
range checking kevin carter Microsoft Excel Misc 2 9th Dec 2003 12:07 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:54 AM.