Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default How to tell whether any cell within a Range has non-empty contents

I am writing a VSTO addin for Excel 2003 that reads data from a
database and populates a range of cells. I want to be able to detect
if there is any existing data within any of the cells in the range, so
that I can prompt the user whether to overwrite or insert rows/
columns. The amount of data returned could be different each time.

Is there a method that will tell me if any cell in a range is occupied
(including a formula), and which cell it is within the range?

Thanks for the help.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 434
Default How to tell whether any cell within a Range has non-empty contents

hi, Cullen Morris !

from within excel, I would use something like the following:

Dim CellsInUse As Range
With Range("a1:d30")
On Error Resume Next
Set CellsInUse = Union( _
.SpecialCells(xlCellTypeConstants), _
.SpecialCells(xlCellTypeFormulas))
On Error GoTo 0
End With
If CellsInUse Is Nothing Then Exit Sub
MsgBox "There are non-empty cells in the range !!!" & _
vbCr & CellsInUse.Address
Set CellsInUse = Nothing

hth,
hector.

__ OP __
I am writing a VSTO addin for Excel 2003 that reads data from a database and populates a range of cells.
I want to be able to detectif there is any existing data within any of the cells in the range
so that I can prompt the user whether to overwrite or insert rows/columns.
The amount of data returned could be different each time.
Is there a method that will tell me if any cell in a range is occupied (including a formula)
and which cell it is within the range?

Thanks for the help.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default How to tell whether any cell within a Range has non-emptycontents

On Sep 26, 10:29*pm, "Héctor Miguel"
wrote:
hi, Cullen Morris !

from within excel, I would use something like the following:

* Dim CellsInUse As Range
* With Range("a1:d30")
* * On Error Resume Next
* * Set CellsInUse = Union( _
* * * .SpecialCells(xlCellTypeConstants), _
* * * .SpecialCells(xlCellTypeFormulas))
* * On Error GoTo 0
* End With
* If CellsInUse Is Nothing Then Exit Sub
* MsgBox "There are non-empty cells in the range !!!" & _
* * vbCr & CellsInUse.Address
* Set CellsInUse = Nothing

hth,
hector.

__ OP __

I am writing a VSTO addin for Excel 2003 that reads data from a database and populates a range of cells.
I want to be able to detectif there is any existing data within any of the cells in the range
so that I can prompt the user whether to overwrite or insert rows/columns.
The amount of data returned could be different each time.
Is there a method that will tell me if any cell in a range is occupied (including a formula)
and which cell it is within the range?


Thanks for the help.


Thanks for the help!
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
Copy cell contents in empty rows below it till any unempty row com vtmalhan Excel Discussion (Misc queries) 1 February 11th 08 11:26 AM
Macro to clear range contents when cell contents are changed by us Steve E Excel Programming 12 February 22nd 07 09:09 PM
How do I set one cell to equal another if its contents are empty? APElizondo Excel Worksheet Functions 2 October 3rd 06 02:03 AM
Finding next empty empty cell in a range of columns UncleBun Excel Programming 1 January 13th 06 11:22 PM
Filling empty cells with contents from another cell [email protected] Excel Programming 5 October 3rd 05 09:48 PM


All times are GMT +1. The time now is 05:26 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"