Results 1 to 18 of 18

Assign different named ranges based on variable number of entries

Threaded View

  1. #1
    Registered User
    Join Date
    10-02-2013
    Location
    St. Paul, Minnesota
    MS-Off Ver
    Excel 2010
    Posts
    28

    Assign different named ranges based on variable number of entries

    Hi All

    I’m still fairly new to VB code, so I’ve been trying to practice by creating spreadsheets to make my life at work easier.

    This spreadsheet will be used as a template each year. What I’d like to do is use VB to create named ranges based on each State grouping (i.e. Range(“$A16:$A21”)=“Arkansas”, Range(“$A22:$A24”)=”Connecticut”, etc.).

    I’ve tried to code using VB to name each State’s range. I'm sure I've completely fubar'd this, so I need some expert help. The code below is where I appear to be running into problems….

    Sub CalculateReimb()
    
    Dim cell As Range, AgencyRng As Range, y As Integer
    
    Set AgencyRng = Range("$A16:$A48")
    
    For Each cell In AgencyRng
    
    y = Application.WorksheetFunction.CountIf(AgencyRng, cell) - 1
    
    ActiveWorkbook.Names.Add Name:=cell, refersto:=Worksheets("Calc to begin Rd 3"). _
        Range(cell & ":" & cell.Offset(, y))
    
    Next cell
    
    End Sub
    Obviously, each time a user enters data for a new year, each State will be assigned different ranges than the year before. I have tried to create the VB sub, but I can’t seem to get the hang of it yet.

    I’ve attached a sample spreadsheet for reference.
    Any ideas?
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] assign a value to a named variable of a spread sheet
    By ceussk in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-14-2013, 08:29 AM
  2. [SOLVED] How Do I Assign Attributes to Entries Based on Category?
    By kelman17 in forum Excel General
    Replies: 6
    Last Post: 06-10-2013, 09:31 PM
  3. [SOLVED] Using text entries to reference named ranges
    By dow400 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 02-20-2013, 09:07 AM
  4. [SOLVED] Sorting rows of data based off a single column for a variable number of entries.
    By soxcrates in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-28-2012, 12:31 PM
  5. Replies: 2
    Last Post: 07-24-2012, 11:47 AM

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