Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.office.developer.vba,microsoft.public.office.developer.com.add_ins,microsoft.public.office.developer.automation,microsoft.public.excel.programming
LF LF is offline
external usenet poster
 
Posts: 32
Default Working with a Range object

Hello,

In a C++ COM add-in for Excel I need to do something with all the cells on a
worksheet. I saw that I can use Worksheet.UsedRange. However, this is a
read-only property. Does this mean that the range itself is read-only, or
the cells that are covered by this range (I hope the cells are writable)?

Then, assuming I've got a Range object, how do I iterate all the cells in it
an do my processing on each cell?

Regards and thanks,
Levente


  #2   Report Post  
Posted to microsoft.public.office.developer.vba,microsoft.public.office.developer.com.add_ins,microsoft.public.office.developer.automation,microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Working with a Range object

The UsedRange property is read-only, but the cells in it may be writable,
depending on protection/locked settings.

Dim Cell as range
for each cell in Activesheet.usedrange
debug.print cell.address
next

NickHK

"LF" wrote in message
...
Hello,

In a C++ COM add-in for Excel I need to do something with all the cells on

a
worksheet. I saw that I can use Worksheet.UsedRange. However, this is a
read-only property. Does this mean that the range itself is read-only, or
the cells that are covered by this range (I hope the cells are writable)?

Then, assuming I've got a Range object, how do I iterate all the cells in

it
an do my processing on each cell?

Regards and thanks,
Levente




  #3   Report Post  
Posted to microsoft.public.office.developer.vba,microsoft.public.office.developer.com.add_ins,microsoft.public.office.developer.automation,microsoft.public.excel.programming
LF LF is offline
external usenet poster
 
Posts: 32
Default Working with a Range object

Nick,

Thanks fro confirming that the celss may be writable. However, this VB
sample is of no use for me. I need to iterate the cells using C++. I have an
Excel::_Worksheet interface pointer. Can you please explain what the VB
for_each gets translated into in this case? Thanks.

Best regards,
Levente


"NickHK" wrote in message
...
The UsedRange property is read-only, but the cells in it may be writable,
depending on protection/locked settings.

Dim Cell as range
for each cell in Activesheet.usedrange
debug.print cell.address
next

NickHK

"LF" wrote in message
...
Hello,

In a C++ COM add-in for Excel I need to do something with all the cells
on

a
worksheet. I saw that I can use Worksheet.UsedRange. However, this is a
read-only property. Does this mean that the range itself is read-only, or
the cells that are covered by this range (I hope the cells are writable)?

Then, assuming I've got a Range object, how do I iterate all the cells in

it
an do my processing on each cell?

Regards and thanks,
Levente






  #4   Report Post  
Posted to microsoft.public.office.developer.vba,microsoft.public.office.developer.com.add_ins,microsoft.public.office.developer.automation,microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Working with a Range object

You'd have to ask in a C++ group what that would be.
Or use
Dim i As Long

With ActiveSheet.UsedRange
For i = 1 To .Cells.Count
MsgBox .Item(i).Address
Next
End With

NickHK

"LF" wrote in message
...
Nick,

Thanks fro confirming that the celss may be writable. However, this VB
sample is of no use for me. I need to iterate the cells using C++. I have

an
Excel::_Worksheet interface pointer. Can you please explain what the VB
for_each gets translated into in this case? Thanks.

Best regards,
Levente


"NickHK" wrote in message
...
The UsedRange property is read-only, but the cells in it may be

writable,
depending on protection/locked settings.

Dim Cell as range
for each cell in Activesheet.usedrange
debug.print cell.address
next

NickHK

"LF" wrote in message
...
Hello,

In a C++ COM add-in for Excel I need to do something with all the cells
on

a
worksheet. I saw that I can use Worksheet.UsedRange. However, this is a
read-only property. Does this mean that the range itself is read-only,

or
the cells that are covered by this range (I hope the cells are

writable)?

Then, assuming I've got a Range object, how do I iterate all the cells

in
it
an do my processing on each cell?

Regards and thanks,
Levente








  #5   Report Post  
Posted to microsoft.public.office.developer.vba,microsoft.public.office.developer.com.add_ins,microsoft.public.office.developer.automation,microsoft.public.excel.programming
LF LF is offline
external usenet poster
 
Posts: 32
Default Working with a Range object

Nick,

The Workshhet-Cells property returns a Range object. And although
Range-Count returns the number of cells (I guess), I cannot simply Index
using Range-GetItem() because this methods wants a rox and a column index.
And I do not know from where to where are the cells included in the range.
Not to mention that a range object could contain multiple areas, each one
for an isle of cells.

Thus the question remains: how can I reliably iterate all the cells in a
Range object?

Regards and thanks,
Levente


"NickHK" wrote in message
...
You'd have to ask in a C++ group what that would be.
Or use
Dim i As Long

With ActiveSheet.UsedRange
For i = 1 To .Cells.Count
MsgBox .Item(i).Address
Next
End With

NickHK

"LF" wrote in message
...
Nick,

Thanks fro confirming that the celss may be writable. However, this VB
sample is of no use for me. I need to iterate the cells using C++. I have

an
Excel::_Worksheet interface pointer. Can you please explain what the VB
for_each gets translated into in this case? Thanks.

Best regards,
Levente


"NickHK" wrote in message
...
The UsedRange property is read-only, but the cells in it may be

writable,
depending on protection/locked settings.

Dim Cell as range
for each cell in Activesheet.usedrange
debug.print cell.address
next

NickHK

"LF" wrote in message
...
Hello,

In a C++ COM add-in for Excel I need to do something with all the
cells
on
a
worksheet. I saw that I can use Worksheet.UsedRange. However, this is
a
read-only property. Does this mean that the range itself is read-only,

or
the cells that are covered by this range (I hope the cells are

writable)?

Then, assuming I've got a Range object, how do I iterate all the cells

in
it
an do my processing on each cell?

Regards and thanks,
Levente












  #6   Report Post  
Posted to microsoft.public.office.developer.vba,microsoft.public.office.developer.com.add_ins,microsoft.public.office.developer.automation,microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Working with a Range object

You can test the .Areas.Count property of the range.
But the UsedRange is always one 1 area although another may not be.
How you do this in C++ is up to you :

Private Sub CommandButton1_Click()
Dim r As Range
Dim i As Long
Dim j As Long
'Create a range of multiple areas
Set r = Union(Range("A1:B2"), Range("D4:F6"))

With r.Areas
For j = 1 To .Count
With .Item(j)
For i = 1 To .Cells.Count
With .Item(i)
.Select
MsgBox .Address
End With
Next
End With
Next
End With

End Sub

NickHK

"LF" wrote in message
...
Nick,

The Workshhet-Cells property returns a Range object. And although
Range-Count returns the number of cells (I guess), I cannot simply Index
using Range-GetItem() because this methods wants a rox and a column

index.
And I do not know from where to where are the cells included in the range.
Not to mention that a range object could contain multiple areas, each one
for an isle of cells.

Thus the question remains: how can I reliably iterate all the cells in a
Range object?

Regards and thanks,
Levente


"NickHK" wrote in message
...
You'd have to ask in a C++ group what that would be.
Or use
Dim i As Long

With ActiveSheet.UsedRange
For i = 1 To .Cells.Count
MsgBox .Item(i).Address
Next
End With

NickHK

"LF" wrote in message
...
Nick,

Thanks fro confirming that the celss may be writable. However, this VB
sample is of no use for me. I need to iterate the cells using C++. I

have
an
Excel::_Worksheet interface pointer. Can you please explain what the VB
for_each gets translated into in this case? Thanks.

Best regards,
Levente


"NickHK" wrote in message
...
The UsedRange property is read-only, but the cells in it may be

writable,
depending on protection/locked settings.

Dim Cell as range
for each cell in Activesheet.usedrange
debug.print cell.address
next

NickHK

"LF" wrote in message
...
Hello,

In a C++ COM add-in for Excel I need to do something with all the
cells
on
a
worksheet. I saw that I can use Worksheet.UsedRange. However, this

is
a
read-only property. Does this mean that the range itself is

read-only,
or
the cells that are covered by this range (I hope the cells are

writable)?

Then, assuming I've got a Range object, how do I iterate all the

cells
in
it
an do my processing on each cell?

Regards and thanks,
Levente












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
Working with the range object [email protected] Excel Discussion (Misc queries) 2 November 27th 07 09:05 AM
Working with the range object [email protected] Excel Discussion (Misc queries) 1 November 26th 07 04:29 PM
returning pivottable object from a range object Grant Excel Programming 2 September 27th 04 02:22 AM
Range object to Array object conversion Myrna Larson[_2_] Excel Programming 1 August 1st 03 02:27 AM
Range object to Array object conversion Alan Beban[_3_] Excel Programming 0 August 1st 03 01:24 AM


All times are GMT +1. The time now is 06:27 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"