+ Reply to Thread
Results 1 to 4 of 4

Help setting variable range name

  1. #1
    Registered User
    Join Date
    04-24-2004
    Location
    Wisconsin, USA
    MS-Off Ver
    2007
    Posts
    76

    Help setting variable range name

    Hello,

    I am attempting to create a VBA routine that defines a data range (LookupDate). The first cell in the range remains constant (P33); however, the last row changes. I have a cell (S17) that displays the last row where the range should end. I believe I am looking for a way to change the row marker (R87) in the following line of code to be based on the value in cell S17

    ActiveWorkbook.Names.Add Name:="LookupDate", RefersToR1C1:="=Amortize!R33C16:R87C16"

    Something like
    ActiveWorkbook.Names.Add Name:="LookupDate", RefersToR1C1:="=Amortize!R33C16:RS17C16"
    Or
    ActiveWorkbook.Names.Add Name:="LookupDate", RefersToR1C1:="=Amortize!R33C16:R�S17�C16"
    Or
    ActiveWorkbook.Names.Add Name:="LookupDate", RefersToR1C1:="=Amortize!R33C16:R&�S17�C16"
    Or
    ActiveWorkbook.Names.Add Name:="LookupDate", RefersToR1C1:="=Amortize!R33C16:R" & S17 & "C16"
    Or
    ?????


    Here is my current (erroneous) macro:
    Please Login or Register  to view this content.
    Any suggestions would be appreciated. Thanks

    Thanks for viewing,
    Steve K.
    Last edited by esskaykay; 03-28-2024 at 11:22 AM.

  2. #2
    Registered User
    Join Date
    04-24-2004
    Location
    Wisconsin, USA
    MS-Off Ver
    2007
    Posts
    76

    Re: Help setting variable range name

    I think I figured out my answer (I am slowly getting better at this). I needed to add the Range parameter. It appears to be working. . .

    ActiveWorkbook.Names.Add Name:="LookupDate", RefersToR1C1:="=Amortize!R33C16:R" & Range("S17") & "C16"
    Last edited by esskaykay; 03-28-2024 at 03:36 PM.

  3. #3
    Forum Expert bebo021999's Avatar
    Join Date
    07-22-2011
    Location
    Vietnam
    MS-Off Ver
    Excel 2016
    Posts
    9,466

    Re: Help setting variable range name

    Alternative way:

    PHP Code: 
    Sub LookupRange()
        
    Dim LookupDate As Range
        Dim LastRow 
    As Long
        
        
    ' Get the last row number from cell S17
        LastRow = Range("S17").Value
        
        ' 
    Define the range using the constant first cell (P33) and the dynamically determined last row
        Set LookupDate 
    Sheets("Amortize").Range("P33:R" LastRow)
        
        
    ' Add the defined range as a named range
        ThisWorkbook.Names.Add Name:="LookupDate", RefersTo:=LookupDate
        
    End Sub 
    Quang PT

  4. #4
    Registered User
    Join Date
    04-24-2004
    Location
    Wisconsin, USA
    MS-Off Ver
    2007
    Posts
    76

    Re: Help setting variable range name

    Thank you bebo - much appreciated.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] deleting cells (shift up) - setting range address to range variable
    By vba_php in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-12-2020, 09:31 AM
  2. Replies: 2
    Last Post: 09-01-2017, 05:43 PM
  3. Setting Range Via Variable
    By WanderingJack in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-25-2015, 04:22 AM
  4. [SOLVED] Setting a variable range with a variable sheet name. Hmm?
    By starcraftbud in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-11-2013, 11:46 AM
  5. Replies: 15
    Last Post: 09-10-2013, 05:31 AM
  6. [SOLVED] setting a range as a variable
    By Zealotwraith in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-09-2013, 12:27 PM
  7. setting a range variable
    By Lazhal in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-30-2010, 01:50 PM

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.6.0 RC 1