PC Review


Reply
Thread Tools Rate Thread

Checking for non-blank cells in named range

 
 
=?Utf-8?B?QmFyYiBSZWluaGFyZHQ=?=
Guest
Posts: n/a
 
      13th Oct 2006
I have a range, let's call it myRange that's cells B22:B24 in my worksheet.
I need to check that these cells are all not blank before doing something
else. I'm not sure how to write the code to check that all are non-blank.
Any suggestions?

Thanks
 
Reply With Quote
 
 
 
 
=?Utf-8?B?SmltIFRob21saW5zb24=?=
Guest
Posts: n/a
 
      13th Oct 2006
Here is a simple function that will tell you if a range of cells contains any
blanks.

Public Function HasBlanks(ByVal rng As Range) As Boolean
Dim rngBlanks As Range

On Error Resume Next
Set rngBlanks = rng.SpecialCells(xlCellTypeBlanks)
On Error GoTo 0
If rngBlanks Is Nothing Then
HasBlanks = False
Else
HasBlanks = True
End If
End Function

You can use it like this.
if hasblanks(sheet1.Range("B22:B24")) = true then
msgbox "you need to fill some stuff in!"
else
'do some stuff
end if
--
HTH...

Jim Thomlinson


"Barb Reinhardt" wrote:

> I have a range, let's call it myRange that's cells B22:B24 in my worksheet.
> I need to check that these cells are all not blank before doing something
> else. I'm not sure how to write the code to check that all are non-blank.
> Any suggestions?
>
> Thanks

 
Reply With Quote
 
Tom Ogilvy
Guest
Posts: n/a
 
      13th Oct 2006
if application.CountA(Range("B22:B24")) = 3 then
' all filled
else
msgbox Application.CountBlank(Range("B22:B24")) & " blank cells"
end if

Replae "B22:B24" with myRange if it is a range variable or

Range("myrange") if it is a named range.

if the range is variable, you could do

if application.CountA(Range("B22:B24")) = Range("B22:B24").Count then


or use CountBlank in the original test and check for a value of zero.

--
Regards,
Tom Ogilvy


"Barb Reinhardt" <(E-Mail Removed)> wrote in message
news:A712C6F5-3B31-4341-AB70-(E-Mail Removed)...
>I have a range, let's call it myRange that's cells B22:B24 in my worksheet.
> I need to check that these cells are all not blank before doing something
> else. I'm not sure how to write the code to check that all are
> non-blank.
> Any suggestions?
>
> Thanks



 
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 for non blank cells in named range =?Utf-8?B?QmFyYiBSZWluaGFyZHQ=?= Microsoft Excel Programming 1 13th Oct 2006 03:32 PM
Checking for non-blank cells in named range =?Utf-8?B?QmFyYiBSZWluaGFyZHQ=?= Microsoft Excel Programming 0 13th Oct 2006 02:42 PM
Dynamic Named Range with blank cells =?Utf-8?B?dGp0amp0anQ=?= Microsoft Excel Misc 3 5th Oct 2005 08:10 PM
Blank cells in named range- how to ignore them when making my graph? Help plz! KR Microsoft Excel Misc 0 24th Aug 2005 02:35 PM
Checking for all blank cells in a range orcolumn. =?Utf-8?B?TWlrZXk=?= Microsoft Excel Programming 1 30th Jun 2005 03:59 PM


Features
 

Advertising
 

Newsgroups
 


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