K
Ken McLennan
[This followup was posted to and a copy was sent to the cited author.]
G'day there One & All,
I'm back on the group with a question again, but this one's more
for curiosity than for need.
I'm sure that I've found a bug in Excel. It's more likely just a
bug in the way I perceive that Excel should work, but I'd rather blame
Microsoft than admit to a personal deficiency =)
What I have is a sheet with, amongst other things, a range object
consisting of 2 discontiguous rows of 13 cells each. Ie:
Set nGrid = Union(Sheet1.Range(Cells(ntrow, gsLft), Cells(ntrow,
gsLft + 12)), Sheet1.Range(Cells(nbrow, gsLft), Cells(nbrow, gsLft +
12)))
ntrow = top row
nbrow = bottom row
gsleft = left column
The variables give me the following address for nGrid -
$D$22:$P$22,$D$25:$P$25
That bit works fine. If I tell nGrid to have a green background
and glow in the dark then both sets of cells do exactly that.
I want to have the cells contain the numbers 1 to 26. Obviously,
13 in each row. I thought that I could use the ".item" property but I
couldn't figure out a way to do so. I then decided on to use the old
"For x = 1 to 26" technique thusly:
Dim x As Integer
For x = 1 To 26
nGrid.Cells(x).Value = x
Next
That worked fine for the first 13 cells, but then it all went
awry. The second row of 'x' values went into the correct columns but in
the row immediately underneath the first:
1 2 3 4 5 6 7 8 9 10 11 12 13
--------------------------------------
14 15 16 17 18 19 20 21 22 23 24 25 26
When it should have been:
1 2 3 4 5 6 7 8 9 10 11 12 13
--------------------------------------
--------------------------------------
--------------------------------------
14 15 16 17 18 19 20 21 22 23 24 25 26
A couple of debug.prints before & after for loop indicate that
Excel is well aware of the address, giving the same as detailed above.
However it doesn't write the values into row 25, but into 23!!! It's
obvious that the correct address is being read as indicated by the green
glowing in the dark. What gives? Why doesn't it write the values into
the correct row? The address is obviously being read ok as the columns
are all correct.
It's easy to get around, by just writing to the nominated row, but
I don't understand the mechanism behind why this doesn't work. Any ideas
anyone?
See ya
Ken McLennan
Qld, Australia
G'day there One & All,
I'm back on the group with a question again, but this one's more
for curiosity than for need.
I'm sure that I've found a bug in Excel. It's more likely just a
bug in the way I perceive that Excel should work, but I'd rather blame
Microsoft than admit to a personal deficiency =)
What I have is a sheet with, amongst other things, a range object
consisting of 2 discontiguous rows of 13 cells each. Ie:
Set nGrid = Union(Sheet1.Range(Cells(ntrow, gsLft), Cells(ntrow,
gsLft + 12)), Sheet1.Range(Cells(nbrow, gsLft), Cells(nbrow, gsLft +
12)))
ntrow = top row
nbrow = bottom row
gsleft = left column
The variables give me the following address for nGrid -
$D$22:$P$22,$D$25:$P$25
That bit works fine. If I tell nGrid to have a green background
and glow in the dark then both sets of cells do exactly that.
I want to have the cells contain the numbers 1 to 26. Obviously,
13 in each row. I thought that I could use the ".item" property but I
couldn't figure out a way to do so. I then decided on to use the old
"For x = 1 to 26" technique thusly:
Dim x As Integer
For x = 1 To 26
nGrid.Cells(x).Value = x
Next
That worked fine for the first 13 cells, but then it all went
awry. The second row of 'x' values went into the correct columns but in
the row immediately underneath the first:
1 2 3 4 5 6 7 8 9 10 11 12 13
--------------------------------------
14 15 16 17 18 19 20 21 22 23 24 25 26
When it should have been:
1 2 3 4 5 6 7 8 9 10 11 12 13
--------------------------------------
--------------------------------------
--------------------------------------
14 15 16 17 18 19 20 21 22 23 24 25 26
A couple of debug.prints before & after for loop indicate that
Excel is well aware of the address, giving the same as detailed above.
However it doesn't write the values into row 25, but into 23!!! It's
obvious that the correct address is being read as indicated by the green
glowing in the dark. What gives? Why doesn't it write the values into
the correct row? The address is obviously being read ok as the columns
are all correct.
It's easy to get around, by just writing to the nominated row, but
I don't understand the mechanism behind why this doesn't work. Any ideas
anyone?
See ya
Ken McLennan
Qld, Australia