Consulting

Results 1 to 13 of 13

Thread: Dynamically Update Defined Names Range

  1. #1
    VBAX Regular
    Joined
    Dec 2012
    Posts
    55
    Location

    Dynamically Update Defined Names Range

    Hi ExcelGeeks

    Can some one help me in changing the named ranges dynamically.

    Attached the sample file with requirement.

    Best
    Rem0
    Attached Files Attached Files

  2. #2
    VBAX Tutor
    Joined
    Jun 2012
    Posts
    269
    Location
    RemOram,
    You can use the following function to re-name a range. Your post was not clear about the conditions that would cause you to activate this function, so I will leave that to you, or you can explain further those conditions.

    For example, if you want this done when the user adds a new row, you could call this from the worksheet change event etc...

    Oh, the function will return true if it worked, false if there was a problem...

    [VBA]
    Function reName(ByRef sDefinedName As String, ByRef rng As Range, ByRef sht As Worksheet) As Boolean

    On Error GoTo errHandler:
    ActiveWorkbook.Names(sDefinedName).RefersTo = sht.Name & "!" & rng.Address

    reName = True
    Exit Function
    errHandler:
    reName = False

    End Function
    [/VBA]

  3. #3
    if the sheetname contains a space you're required to add ' around it...
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  4. #4
    VBAX Regular
    Joined
    Dec 2012
    Posts
    55
    Location
    Hi CodeNinja

    ManyThanks for looking in to this and sorry about the vague information.

    I can have a command button to facilitate this code. Can you update the code to the sample file as i have only limited knowledge about vba.

    Hi Jan Karel

    Thanks for the info.

    Best
    Rem0

  5. #5
    VBAX Tutor
    Joined
    Jun 2012
    Posts
    269
    Location
    RemOram,
    A command button would work, but how would you determine exactly what range you want to use in the named ranges? Would there only be named ranges for "BS", "CFG", "MSB", "ULT", and "WM" or should this dynamically look for anything past RMSG/RMS/ and name a range for that?

    By the way, good point Jan Karl, you are 100% correct, and I will add that to the function. Thanks.

    CodeNinja.

  6. #6
    VBAX Regular
    Joined
    Dec 2012
    Posts
    55
    Location
    Hi CodeNinja

    ManyThanks!

    I'm thinking of a way read the string in each cell, for example for RMSG/RMS/BS group first 11 characters common.

    Is there a way to use the string?

    Best
    Rem0

  7. #7
    snb
    Guest
    You'd better dive into the fundamentals of VBA first.

  8. #8
    VBAX Tutor
    Joined
    Jun 2012
    Posts
    269
    Location
    I am really trying to learn the fundamentals of VBA snb

  9. #9
    snb
    Guest
    @CodeNinja

    Unless I use @name, I am addressing the OP in his/her thread.
    Although diving into fundamentals isn't a bad thing to do for anybody, I wasn't addressing you, codeninja.

  10. #10
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,954
    Location
    Rem, for code to dynamical set the range to a named range, there must be logic. You must tell us the rules since it is not obvious from your example.

    You would be better off breaking those into columns and use a dynamic range formula method for each column. Then, no VBA would be needed.

  11. #11
    VBAX Tutor
    Joined
    Jun 2012
    Posts
    269
    Location
    Quote Originally Posted by snb
    @CodeNinja

    Unless I use @name, I am addressing the OP in his/her thread.
    Although diving into fundamentals isn't a bad thing to do for anybody, I wasn't addressing you, codeninja.
    Ya, I knew... I was being silly snb... My very weird sense of humor.

  12. #12
    snb
    Guest
    @CN

    sorry for misinterpreting you......

  13. #13
    VBAX Regular
    Joined
    Dec 2012
    Posts
    55
    Location
    Hi Ken

    Thanks a lot for the tip.

    I'm really not that familiar with Offset formula however managed to obtain the result.

    Thanks a Trillion....

    Best
    Rem0

Posting Permissions

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