get selected row numbers with filter

masterx7

New Member
Joined
Nov 2, 2016
Messages
16
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?
jj7dpb

jj7dpb


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
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

Forum statistics

Threads
1,216,119
Messages
6,128,946
Members
449,480
Latest member
yesitisasport

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top