+ Reply to Thread
Results 1 to 3 of 3

Multiple Dynamic Named Ranges w/ Blank Cells Auto Update on Resize

Hybrid View

  1. #1
    Registered User
    Join Date
    09-23-2019
    Location
    Yorkshire, England
    MS-Off Ver
    2013, 2016, 365
    Posts
    5

    Multiple Dynamic Named Ranges w/ Blank Cells Auto Update on Resize

    Hi all,

    I'm new to the forum and returning to Excel for the first time in approx 15 years. Very rusty w/ basic knowledge.

    I currently have a spreadsheet similar to the very simple example attached. I have VBA code as below that forces text in certain ranges to uppercase.

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    Application.ScreenUpdating = False
    
    If Target.Cells.Count > 1 Or Target.HasFormula Then Exit Sub
    
        On Error Resume Next
        If Not Intersect(Target, Range("D5:H19,J5:N19,P5:T19,V5:Z19")) Is Nothing Then
        Application.EnableEvents = False
        Target = UCase(Target)
        Application.EnableEvents = True
        End If
        On Error GoTo 0
        
    Application.ScreenUpdating = True
    
    End Sub
    However, I would like to have dynamic named ranges so that the code updates when rows/columns are inserted/deleted on the worksheet.

    As this spreadsheet is essentially a template, the ranges will begin with all blank cells and even when filled in will still have some blank cells. I currently have the following two formulas that return the correct first and last cells of a range BUT how do I put them together to specify the range itself? If I try to put a colon between them I get an error.

    See spreadsheet for more explanation.

    CELL("address",OFFSET(Aut_1, 1, 0,))
    CELL("address",OFFSET(Oct_HT,COUNTA($B:$B), -1,))
    Please ask if any more clarification is needed.

    Thank you in advance.
    Attached Files Attached Files
    Last edited by finkbee; 09-24-2019 at 09:17 AM. Reason: Changed Things Up

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,933

    Re: Multiple Dynamic Named Ranges w/ Blank Cells Auto Update on Resize

    Name	Refers to:
    
    Aut_1	=OFFSET(Sheet1!$A$1,4,MATCH("A1",Sheet1!$A$3:$AA$3,0)-1,COUNTA(Sheet1!$B:$B)-1,SMALL(IF(Sheet1!$D$3:$AA$3="HT",COLUMN(Sheet1!$D$3:$AA$3)),1)-MATCH("a1",Sheet1!$A$3:$AA$3,0))
    Aut_2	=OFFSET(Sheet1!$A$1,4,MATCH("A2",Sheet1!$A$3:$AA$3,0)-1,COUNTA(Sheet1!$B:$B)-1,SMALL(IF(Sheet1!$D$3:$AA$3="HT",COLUMN(Sheet1!$D$3:$AA$3)),2)-MATCH("A2",Sheet1!$A$3:$AA$3,0))
    Spr_1	=OFFSET(Sheet1!$A$1,4,MATCH("S1",Sheet1!$A$3:$AA$3,0)-1,COUNTA(Sheet1!$B:$B)-1,SMALL(IF(Sheet1!$D$3:$AA$3="HT",COLUMN(Sheet1!$D$3:$AA$3)),3)-MATCH("S1",Sheet1!$A$3:$AA$3,0))
    Spr_2	=OFFSET(Sheet1!$A$1,4,MATCH("S2",Sheet1!$A$3:$AA$3,0)-1,COUNTA(Sheet1!$B:$B)-1,SMALL(IF(Sheet1!$D$3:$AA$3="HT",COLUMN(Sheet1!$D$3:$AA$3)),4)-MATCH("S2",Sheet1!$A$3:$AA$3,0))
    Option Explicit
    Private Sub Worksheet_Change(ByVal Target As Range)
        Dim Group As Variant
        If Target.Cells.Count > 1 Or Target.HasFormula Then Exit Sub
    
        For Each Group In Split("Aut_1,Aut_2,Spr_1,Spr_2", ",")
            If Not Intersect(Target, Range(Group)) Is Nothing Then
                With Application
                    .EnableEvents = False
                    .ScreenUpdating = False
                End With
                Target = UCase(Target)
                Exit For
            End If
        Next Group
        With Application
            .EnableEvents = True
            .ScreenUpdating = True
        End With
    End Sub
    Last edited by protonLeah; 09-25-2019 at 11:33 PM.
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    09-23-2019
    Location
    Yorkshire, England
    MS-Off Ver
    2013, 2016, 365
    Posts
    5

    Re: Multiple Dynamic Named Ranges w/ Blank Cells Auto Update on Resize

    Thank you. I have implemented this into my actual spreadsheet after factoring in the renaming etc. It is working ok. Just hope I don't break things when I start messing with the rest of my sheet.

    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] Help modify code to auto-fit multiple named ranges
    By onmyway in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-24-2015, 01:06 PM
  2. [SOLVED] Setting up dynamic named ranges in code
    By j_Southern in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 11-04-2014, 01:03 PM
  3. Replies: 0
    Last Post: 10-15-2012, 07:24 AM
  4. Advanced filter with blank cells / Dynamic named range with blank cells
    By Jason_2112 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-15-2010, 12:06 PM
  5. Assigning dynamic named ranges to listfillrange via macro code
    By Schwizer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-30-2007, 11:44 AM
  6. [SOLVED] Resize Named Ranges Help
    By Ray Batig in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-01-2006, 08:35 AM
  7. Dynamic Named Ranges with Blank Cells
    By andibevan in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 01-17-2005, 01:48 PM

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