deselect row/column from multiple selection

A

Alan C

Selecting multiple non-adjacent rows with control click. How do I deselect
one of them.
 
G

Gary''s Student

Try this macro:

Sub DropARow()
Set r1 = Selection
n = Application.InputBox(prompt:="enter row# to be de-selected", Type:=1)
Set r2 = Range(n & ":" & n)
Set r3 = Nothing
For Each rr In r1
If Intersect(rr, r2) Is Nothing Then
If r3 Is Nothing Then
Set r3 = rr
Else
Set r3 = Union(r3, rr)
End If
End If
Next
r3.Select
End Sub
 
G

Gord Dibben

And a couple more from Chip Pearson.

Sub UnSelectActiveCell()
Dim rng As Range
Dim FullRange As Range
'Chip Pearson
If Selection.Cells.Count > 1 Then
For Each rng In Selection.Cells
If rng.Address <> ActiveCell.Address Then
If FullRange Is Nothing Then
Set FullRange = rng
Else
Set FullRange = Application.Union(FullRange, rng)
End If
End If
Next rng

If FullRange.Cells.Count > 0 Then
FullRange.Select
End If
End If

End Sub


Sub UnSelectActiveArea()
'Chip Pearson
Dim rng As Range
Dim FullRange As Range
Dim Ndx As Integer
If Selection.Areas.Count > 1 Then
For Each rng In Selection.Areas
If Application.Intersect(ActiveCell, rng) Is Nothing Then
If FullRange Is Nothing Then
Set FullRange = rng
Else
Set FullRange = Application.Union(FullRange, rng)
End If
End If
Next rng
FullRange.Select
End If

End Sub


Gord Dibben MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top