i need to adjust the formulas after copying the entire content of a workbook
from one xls file to another. appartently, the formulas of the cells that
were reffering to other sheets are messed up after a copy (using
Worksheet->Copy). i need to work it around.
Levente,
Iterating through range(s) can be rather time consuming and Excel offer
difference approaches depending on the purpose. What do You want to
achieve
by iterating through all cells?
---------------
With kind regards,
Dennis
Weekly Blog .NET & Excel:
http://xldennis.wordpress.com/
My English site:
http://www.excelkb.com/default.aspx
My Swedish site:
http://www.xldennis.com/
:
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
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
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
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
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
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