PC Review


Reply
Thread Tools Rate Thread

Concise Way To Tell If Range Contains Any Data?

 
 
PeteCresswell
Guest
Posts: n/a
 
      5th Apr 2007
I'm doing validation checking on a spreadsheet whose data will be
imported into a data base if the spreadsheet's formatting and layout
look right.

On a given worksheet, once I think I've found the last row of data,
I'd like to set a .Range=(a whole bunch of cells after what I think is
the last data row) and then check to see if there are any values in
the composite of all those cells.

If there are any values, that would suggest that the worksheet's
format is wanting and I'd inform the user accordingly.

Bottom Line: If I've got a Range, is there a syntactically-simple way
to see if there's any data in it?

 
Reply With Quote
 
 
 
 
Norman Jones
Guest
Posts: n/a
 
      5th Apr 2007
Hi Pete.

Try:

Set Rng = Range("A1:A100")

If Application.CountA(Rng) = 0 Then
MsgBox "Its empty!"
End If


---
Regards,
Norman


"PeteCresswell" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'm doing validation checking on a spreadsheet whose data will be
> imported into a data base if the spreadsheet's formatting and layout
> look right.
>
> On a given worksheet, once I think I've found the last row of data,
> I'd like to set a .Range=(a whole bunch of cells after what I think is
> the last data row) and then check to see if there are any values in
> the composite of all those cells.
>
> If there are any values, that would suggest that the worksheet's
> format is wanting and I'd inform the user accordingly.
>
> Bottom Line: If I've got a Range, is there a syntactically-simple way
> to see if there's any data in it?
>



 
Reply With Quote
 
PeteCresswell
Guest
Posts: n/a
 
      5th Apr 2007
> If Application.CountA(Rng) = 0 Then

That nailed it.... *exactly* what I was trolling for.

Thanks!

 
Reply With Quote
 
PeteCresswell
Guest
Posts: n/a
 
      5th Apr 2007

> Set Rng = Range("A1:A100")


No good deed goes unpunished.

At the risk of wearing out my welcome...

Can I write some kind of loop to iterate through that
range and pick off the Row/Column numbers and cell values
of the offending (i.e. those that have values) cells?

Then I could include at least some of the offending cell locations/
values in my error notification....

 
Reply With Quote
 
Norman Jones
Guest
Posts: n/a
 
      5th Apr 2007
Hi Pete,

Instead of looping, try usung the specialcells method,

For example, if the values did not include formulae, you
could try something like:

'=============>>
Public Sub Tester()
Dim WB As Workbook
Dim SH As Worksheet
Dim Rng As Range

Set WB = Workbooks("MyBook.xls") '<<=== CHANGE
Set SH = WB.Sheets("Sheet1") '<<=== CHANGE
Set Rng = SH.Range("A1:A100") '<<=== CHANGE

On Error Resume Next
Set Rng = Rng.SpecialCells(xlCellTypeConstants)
On Error GoTo 0

If Not Rng Is Nothing Then
'do something, e.g.:
Debug.Print Rng.Address(0, 0)
End If
End Sub
'<<=============



---
Regards,
Norman


"PeteCresswell" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
>> Set Rng = Range("A1:A100")

>
> No good deed goes unpunished.
>
> At the risk of wearing out my welcome...
>
> Can I write some kind of loop to iterate through that
> range and pick off the Row/Column numbers and cell values
> of the offending (i.e. those that have values) cells?
>
> Then I could include at least some of the offending cell locations/
> values in my error notification....
>



 
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
more concise? Todos Menos [MSFT] Microsoft Access 9 15th Mar 2007 07:47 AM
Concise XML Serialization =?Utf-8?B?RGF2ZSBCb29rZXI=?= Microsoft C# .NET 4 13th Jun 2006 01:55 PM
Concise Freeware YotamElal Freeware 5 24th Dec 2005 11:35 AM
Concise loading of data into a hashtable ? mark4asp Microsoft Dot NET Framework 2 28th Sep 2004 06:23 PM
Concise loading of data into a hashtable ? mark4asp Microsoft VB .NET 2 28th Sep 2004 06:23 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:24 AM.