View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Lisa[_10_] Lisa[_10_] is offline
external usenet poster
 
Posts: 5
Default Test if cells are selected

I have a VSTO Excel app where I need to test each row in a range to
see whether the user has selected the cell in column D in that row,
and carry out an operation if they have.

But I'm getting some very erratic results. I tried using For Each
cell as Cell in ActiveWorksheet.Selection.Cells, but that didn't
work. So I went to this:

Dim _col As Integer
Dim _row As Integer
For cellCount As Integer = 0 To .Application.Selection.cells.count -
1
_col = .Application.Selection.cells(cellCount).Column
_row = .Application.Selection.cells(cellCount).Row + 1

The "+ 1" on the row makes no sense to me, but it was off by a row if
I didn't do that.

The problem is, when I select multiple cells in column D, I get weird
results. Two contiguous ones works fine. But if I pick four
contiguous ones, it only sees the first and third. Actually, it
depends on the order in which I select them. And if they aren't
contiguous, it gets even weirder.

Is there a simpler way to do this? A way where instead of going
through the selection and testing the cells to see if they're in the
right column, I can go down that column and check to see if each cell
is selected? I haven't been able to find a Selected or IsSelected
property on cells.

Thanks,
Lisa