Home > Back-end >  Excel VBA - how to detect user selecting an entire row on the worksheet and distinguish if multiple
Excel VBA - how to detect user selecting an entire row on the worksheet and distinguish if multiple

Time:12-14

How do I detect if the user selected an entire row on the worksheet? I would like to return which row is being selected so i can automate some routines - such as copying the data associated with that row.

I only want the automation to be applicable to any one row on the worksheet and not multiple rows. How would I achieve this please?

Appreciate if anyone can point me in the right direction.

Thanks

CodePudding user response:

Put this in the code of the worksheet you want it to run on. You can also check the 'address' property to determine where the selection is. This isn't a full answer, but it should get you started.

Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim bEntireRow As Boolean
With Target   
    bEntireRow = .Address = .EntireRow.Address
End With
    If bEntireRow = True Then
        MsgBox (Target.Rows.Count & " Rows Selected")
    End If
End Sub
  • Related