hi,
I have a code for getting the row numbers of selected cells (I only select cells from column A)
now,
If column A not filtered and I'm dragging the mouse to select several row at once, the code works.
If column A is filtered and I'm choosing the cells one by one with CTRL pressed, the code works.
but, if column A is filtered and I'm dragging the mouse so select several rows, the code doesn't work.
"objSelectionArea.Rows.Count" needs to be value of 1 and not higher.
for example, if filter gives me 2 lines (line 2 and line 9)
the "objSelectionArea.Rows.Count" gives me 10, but if I don't drag the mouse and choose with CTRL and mouse each line, "objSelectionArea.Rows.Count" gives me 1.
what can be done?
Private Sub CommandButton1_Click()
Dim objSelection As Range
Dim objSelectionArea As Range
Dim objCell As Range
Dim intRow As Integer
Dim intActualRow As Integer
Set objSelection = Application.Selection
For Each objSelectionArea In objSelection.Areas
For intRow = 1 To objSelectionArea.Rows.Count Step 1
Set objCell = objSelectionArea.Rows(intRow)
intActualRow = objCell.Row
Next
Next
End Sub
I have a code for getting the row numbers of selected cells (I only select cells from column A)
now,
If column A not filtered and I'm dragging the mouse to select several row at once, the code works.
If column A is filtered and I'm choosing the cells one by one with CTRL pressed, the code works.
but, if column A is filtered and I'm dragging the mouse so select several rows, the code doesn't work.
"objSelectionArea.Rows.Count" needs to be value of 1 and not higher.
for example, if filter gives me 2 lines (line 2 and line 9)
the "objSelectionArea.Rows.Count" gives me 10, but if I don't drag the mouse and choose with CTRL and mouse each line, "objSelectionArea.Rows.Count" gives me 1.
what can be done?
Private Sub CommandButton1_Click()
Dim objSelection As Range
Dim objSelectionArea As Range
Dim objCell As Range
Dim intRow As Integer
Dim intActualRow As Integer
Set objSelection = Application.Selection
For Each objSelectionArea In objSelection.Areas
For intRow = 1 To objSelectionArea.Rows.Count Step 1
Set objCell = objSelectionArea.Rows(intRow)
intActualRow = objCell.Row
Next
Next
End Sub