Closed Thread
Results 1 to 5 of 5

Using VBA to name a range and delete a value instead of named range in wkbk

  1. #1
    Forum Contributor
    Join Date
    04-14-2013
    Location
    Ky
    MS-Off Ver
    Excel 2013
    Posts
    344

    Using VBA to name a range and delete a value instead of named range in wkbk

    ...a continuation from this thread.

    In summary, it seems the .list property (and variants, such as .listindex) don't like it when the "list" is only a single value. So in the linked thread above, I solved my dependence on a named dynamic range in my workbook by using code to name my range, and counting the rows of the range... if rows count = 1 (which will causes an error in the .list property), then do <this> action, but if rows count > 1, then we can use .list.

    So I have an employee list in ws("Admin Menu") in column B. Column A contains a record number (1, 2, 3...) of the number of employees. The list begins on row 2 underneath a header row, and $B$2 is always "Former Employee." In my named dynamic range, the range begins on $B$3. I have a userform to delete an employee. It populates a combo box with a list of the employees, and once one is selected, first finds all matching employees in the worksheet("Data") and changes that employee's names to "Former Employee" - this way data associated with that employee is kept, but records for that employee name are not - and then deletes the employees name from the list on the ws("Admin Menu"). Here's my code:

    Please Login or Register  to view this content.

    I would like to change my routine for the DelEmp_Click() by NOT using the named range "EmpDelList" and instead naming the range with the VBA code used in the initialization (I am keeping the "EmpNameData" range - at least for now)... but the listindex property keeps tripping me up. Any help?

    Again, sorry for not being able to upload a sample file at this time!!

    -HeyInKy

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Using VBA to name a range and delete a value instead of named range in wkbk

    Hello HeyInKy,

    Can you pull together a workbook that shows a before and after example of the your problem and post that?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Contributor
    Join Date
    04-14-2013
    Location
    Ky
    MS-Off Ver
    Excel 2013
    Posts
    344

    Re: Using VBA to name a range and delete a value instead of named range in wkbk

    Sample Project.xlsm

    Use the "Add Employee" button to add the following employees: Employee 1, Employee 2, Employee 3, and Employee 4. (These are already pre-listed on the "Data" worksheet).

    I need the "Delete Employee" to use code - not named ranges in the workbook formulas - to populate the list, and "Former Employee" should not show up either. Then once a name is selected and the delete command is executed, it should remove the selected employee from the list on the "Admin Menu" as well as the corresponding number, and then move everything up 1 row (if the deleted employee was not on the last row).

    It also - and it does this correctly now - find all matching names on the "data" worksheet and change them to "Former Employee."

  4. #4
    Forum Contributor
    Join Date
    04-14-2013
    Location
    Ky
    MS-Off Ver
    Excel 2013
    Posts
    344

    Re: Using VBA to name a range and delete a value instead of named range in wkbk

    Still trying to fix this... here's where I'm at for the delete command button:

    Please Login or Register  to view this content.
    Any help is greatly appreciated.

  5. #5
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    53,048

    Re: Using VBA to name a range and delete a value instead of named range in wkbk

    OP posted in Commercial Services forum, so this thread is now closed
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

Closed Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. How to delete named range with #REF?
    By m3atball in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-02-2014, 02:09 AM
  2. [SOLVED] Using code to delete a named range
    By JimDandy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-29-2013, 05:16 PM
  3. [SOLVED] How to automatically delete named range by name?
    By ks100 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-16-2013, 04:02 PM
  4. Delete Worksheets not on list or in named range?
    By Unpackedrope in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 09-09-2013, 04:12 PM
  5. [SOLVED] delete all oleobjects in named range
    By Willardio in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-24-2012, 02:47 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