Closed Thread
Results 1 to 5 of 5

Changing range for a Named Range VBA

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Changing range for a Named Range VBA

    Hello,

    I have a column that will vary in regards to how many records will be in the range. There could be 20 records in the column or there could be 500 records. I need some code that will change the 'RefersTo' to the proper range. So far I have this code:

    Sub dk2()
    
    Dim PMfilter As String
    
    PMfilter = Sheets("PM Validation").Range(Range(Cells(2, 6), Cells(2, 6)), Range(Cells(65535, 6), Cells(65535, 6)).End(xlUp)).Address
    
    
    ActiveWorkbook.Names("PM_Filter").Delete
    ActiveWorkbook.Names.Add ("PM_Filter"), RefersTo:=PMfilter
    End Sub
    This code first will locate the used range that needs to be re-referenced. The code does go all the way through, however, in the named manager of the workbook, PM_Filter has quotes ("") around the range. When I reference the named range in a data validation list, I get an error stating "The list source must be a delimited list, or a reference to single row or column".

    I did figure out why I was receiving this error, and it's because of the quotes around the reference of the range. For example, after running the code the "Refers To" column in the named manager shows ="$F$2:$F$31". This is the correct reference, however the quotes are what is giving me the issue. Does anyone know how to get rid of these quotes? Maybe the code I have so far isn't the right code to complete my task. Please help!

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,924

    Re: Changing range for a Named Range VBA

    You've created three identical posts. This is against the forum rules, primarily because it wastes a lot of people's time.

    You have answers in the first two.

    Please learn to be patient ... you're likely to get a better response, and not get as many people's backs up.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor
    Join Date
    08-17-2012
    Location
    Richmond, VA
    MS-Off Ver
    Excel 2007
    Posts
    158

    Re: Changing range for a Named Range VBA

    Hey Trever,

    I am sorry there are multiple posts on here. I do post frequently and understand the rules. There was an issue with ExcelForum and every instance I pressed Post, the webpage would error out. So I actually had no idea I posted multiple times. In fact, I didn't think I even had posted one until I received an e-mail! I will delete all other posts.

    Thank you for responding to my issue! I did leave work and have accessed the forum from home, but I will test first thing in the morning.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,924

    Re: Changing range for a Named Range VBA

    Fair enough. The forum has been (a lot) flaky tonight. Pain in the backside!

    Note that you have at least one other reply on one of the other threads (before you delete it)

    Regards, TMS

  5. #5
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Changing range for a Named Range VBA

    Duplicate Thread.

    Thread closed.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

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