+ Reply to Thread
Results 1 to 4 of 4

Thread: Range representing a single row of a named range

  1. #1
    Registered User
    Join Date
    10-29-2007
    Posts
    5

    Question Range representing a single row of a named range

    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

  2. #2
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,639

    Re: Range representing a single row of a named range

    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)

  3. #3
    Cheeky Forum Moderator Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2003, 2007, 2010
    Posts
    3,712

    Re: Range representing a single row of a named range

    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?
    Regards,

    Ron
    Microsoft MVP - Excel
    (Oct 2006 - Sep 2012)

    Click here to see the Forum Rules

  4. #4
    Registered User
    Join Date
    10-29-2007
    Posts
    5

    Re: Range representing a single row of a named range

    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 Then
        
    Application.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 = True
    End If End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0