Hi guys,
I have a named range called "DATA" in a worksheet (its about 100rows x 20cols) and I'm trying to write some code to return a range that represents a single row of range("DATA") based upon the active cell. However I don't want EntireRow.
To do this I'm using Worksheet_SelectionChange(ByVal Target As Range) event and I've used the Intersect function to test that Target is in Range("DATA").
Then for example:
Imagine Range("DATA") is C10:V110. When I select K43 ie Target is K43, I want the range C43:V43 to be returned to a variable in VBA.
How can I do this?
Thanks in advance
Jonny
Something like
Range("Data").Rows(target.row-10)
Hope that helps.
RoyUK
--------
If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need
For Excel Tips & Solutions, free examples and tutorials why not check out my downloads
New members please read & follow the Forum Rules
Remember to mark your questions Solved and rate the answer(s)
Maybe something like this:
Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Not Intersect(Target.Cells(1, 1), [DATA]) Is Nothing Then MsgBox Intersect(Target.Cells(1, 1).EntireRow, [DATA]).Address End If End Sub
That code selects the intersection of the DATA range and
the row of the top-left cell of the new selection.
(in case the user selected a range of cells)
Is that something you can work with?
Thanks guys,
You've solved my problem. Here's what I was trying to do...underline active row of range DATA with a medium weight border.
Private Sub Worksheet_SelectionChange(ByVal Target As Range) 'Thick lines beneath Active Row - but ONLY in DATA range If Not Intersect(Target, Range("DATA")) Is Nothing ThenApplication.ScreenUpdating = False Dim X As Integer Dim rngDATArow As Range X = Range("DATA").Cells(1, 1).Row - Cells(1, 1).Row Set rngDATArow = Range("Data").Rows(Target.Row - X) With Range("DATA") .Borders(xlInsideHorizontal) _ .Weight = xlThin End With With rngDATArow .Borders(xlEdgeBottom) _ .Weight = xlMedium End With Application.ScreenUpdating = TrueEnd If End Sub
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks