+ Reply to Thread
Results 1 to 31 of 31

VBA - Remove text from named range and table

  1. #1
    Registered User
    Join Date
    10-27-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    88

    VBA - Remove text from named range and table

    With a lot of help from you guys I have a macro that performs these 2 tasks:

    1. Adds text to a named range and then sorts the range alphabetically
    2. Adds the same text to a table

    What I now need to do is be able to reverse the procedure and be able to select and item from the named range and remove it from the range and table, then resize the range and table size accordingly.

    I have attached an example sheet showing the existing function to help explain what I am trying to achieve, hope this makes sense let me know if not!
    Attached Files Attached Files

  2. #2
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: VBA - Remove text from named range and table

    What's the Faults sheet all about, what do you need that for?

  3. #3
    Registered User
    Join Date
    10-27-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: VBA - Remove text from named range and table

    The fault sheet contains the named ranges

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: VBA - Remove text from named range and table

    Hi ormerods

    Assign this Code to your Button
    Please Login or Register  to view this content.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  5. #5
    Registered User
    Join Date
    10-27-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: VBA - Remove text from named range and table

    Thanks for your response This is exactly what I am looking to achieve there are however a couple of issues.

    The first of which was my fault, when I created this example sheet I didn’t recreate the layout and naming of the sheets as they actually need to be, I have attached an amended example that shows how the sheet names are actually named and how they relate to the product names in the list of products. In a nutshell the product names in the list would be like “Product_Name” and the sheet name would be “Product Name” (no underscores). Really sorry I forgot to include this in my original request I would really appreciate if you could assist in tweaking the code so it works correctly. I've been trying for 2 hours now and I cannot get it to work

    The second problem I have is that when the fault is removed from the named range in the “Faults” sheet the named range does not get resized so you are left with a blank space at the bottom of the range, is there a way to adjust the range so that this blank space is removed?

    Sorry to be a pain I really appreciate your help with this.
    Attached Files Attached Files

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: VBA - Remove text from named range and table

    Hi ormerods

    In order to do this efficiently I'll need to change the Names of some of your Named Ranges. Is that acceptable?

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: VBA - Remove text from named range and table

    Hi ormerods

    The Code in the attached has been modified to address the issues you described. In order to accommodate the Dropdowns I've changed several of your named ranges

    _3DTV_F to _3DTV
    Mobile_Phone_F to Mobile_Phone
    Printer_F to Printer
    Toaster_F to Toaster
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    10-27-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: VBA - Remove text from named range and table

    Hi there and thanks for your response, sorry for my delay in responding but for some reason I was unsubbed from the thread so didn't get an email notification.

    I'm hoping this won't pose too much of a problem but in my original worksheet I do have lists linking to named ranges for products without the _F, probably should have specified this in my example sheet but I didn't think it would be relevant and didn't want to confuse matters with extraneous information.

    I will have a play around with this when I get a chance tomorrow and let you know if I have any issues, once again thanks for your help.

  9. #9
    Registered User
    Join Date
    10-27-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: VBA - Remove text from named range and table

    All seems to be working perfectly fine now, there was something else I forgot to mention but I managed to tweak the code to sort that myself.

    Thanks for your help.

  10. #10
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: VBA - Remove text from named range and table

    You're welcome...glad I could help. Thanks for the Rep.

  11. #11
    Registered User
    Join Date
    10-27-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: VBA - Remove text from named range and table

    Arrghh, sorry I thought I had solved that problem but it turns out I had not!
    In certain instances there may be a product listed that does not have a corresponding PRODUCTNAME_2F table, how can I tell it to not run the last bit of code (below) if the table does not exist?

    Please Login or Register  to view this content.

  12. #12
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: VBA - Remove text from named range and table

    Hi ormerods

    Which Line of Code is blowing out...I could guess but you tell me (bear in mind...I'm color blind)

  13. #13
    Registered User
    Join Date
    10-27-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: VBA - Remove text from named range and table

    Haha yes sorry that might help

    Please Login or Register  to view this content.

  14. #14
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: VBA - Remove text from named range and table

    Try this
    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    12-11-2013
    Location
    new york,ny
    MS-Off Ver
    Excel 2010
    Posts
    40

    Re: VBA - Remove text from named range and table

    Hello Everyone,

    This seems to be a thread with members who have lots of knowledge in macros. I was wondering if there was one I can create that will replace one range of cells with another range throughout the entire workbook?

    See attached for the situation that I am dealing with.

    Thanks!
    Attached Files Attached Files

  16. #16
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: VBA - Remove text from named range and table

    Hi Joker

    Please start your own Thread in accordance with Forum Rule 2...

    2. Don't post a question in the thread of another member -- start your own. If you feel it's particularly relevant, provide a link to the other thread. You may include up to 3 links to other URLs in a single post, no more, so only link to the relevant pages.

  17. #17
    Registered User
    Join Date
    10-27-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: VBA - Remove text from named range and table

    I inserted the code but it doesn't seem to remove anything from the PRODUCTNAME_2F table now :/

    Would it be easier if I post an example sheet showing the problem?

    I would post the original sheet I'm working on but it contains company information I don't think I would be allowed to sent it..

  18. #18
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: VBA - Remove text from named range and table

    A sample would help...I'll be away for a while...will look at it when I get back

  19. #19
    Registered User
    Join Date
    10-27-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: VBA - Remove text from named range and table

    Remove Fault Example v2.xlsm

    See attached - I have pre selected the product so just click 'Remove Fault' and it should show you the error.

    Thanks, no rush whenever you get the chance.

  20. #20
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: VBA - Remove text from named range and table

    Hi ormerods

    Do you also wish to NOT remove the fault from Faults Sheet if the product listed does not have a corresponding PRODUCTNAME_2F table or should Faults Sheet remain intact?

    If you don't care about Fault Sheets try this Code
    Please Login or Register  to view this content.
    And add this Function to Module 5
    Please Login or Register  to view this content.
    If you DO wish Faults Sheet to remain intact the Test for the existence of the Table will need to happen earlier in the Code...let me know.

  21. #21
    Registered User
    Join Date
    10-27-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: VBA - Remove text from named range and table

    Hi

    Yes unfortunately in all instances the fault needs to be removed from the named range on the 'Faults' sheet, and also the PRODUCTNAME_2F table if it exists.

  22. #22
    Registered User
    Join Date
    10-27-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: VBA - Remove text from named range and table

    Upon re-reading I think I may have misread what you meant in the first sentence, will have a bash at this tomorrow thanks.

  23. #23
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: VBA - Remove text from named range and table

    Or perhaps I didn't ask the question properly. In your example File you have Faults for Mobile_Phone_2 but there is no Table called Mobile_Phone_2.

    Should the Faults be removed for Mobile_Phone_2 or don't you care. The way the Code stands currently, whatever Fault is in Input Cell F2 will be removed. The rest will remain.

  24. #24
    Registered User
    Join Date
    10-27-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: VBA - Remove text from named range and table

    Yes that is exactly what I am looking to achieve, in effect the primary function is to remove the fault from the list on the sheet of faults, then if the product table also exists to remove it from there.

    So it sounds as though what you have changed should do the trick, will confirm tomorrow. Thanks again.

  25. #25
    Registered User
    Join Date
    10-27-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: VBA - Remove text from named range and table

    Ok.... so I tested out what you sent and that seems to be working fine now but I seem to have spotted another issue.

    For some reason when you try to remove a fault that is at the bottom of a table the following line of code throws up an error

    Please Login or Register  to view this content.
    If you open the attached sheet I have preselected fault that will show the error.

    Remove Fault Example v3.xlsm

  26. #26
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: VBA - Remove text from named range and table

    Hi ormerods

    Working with Tables is not one of my strong suits...try this...it appears to work...break it, let me know...
    Please Login or Register  to view this content.

  27. #27
    Registered User
    Join Date
    10-27-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: VBA - Remove text from named range and table

    Hi

    I need to know how to define the variable 'lo'

  28. #28
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: VBA - Remove text from named range and table

    As a ListObject
    Please Login or Register  to view this content.

  29. #29
    Registered User
    Join Date
    10-27-2011
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    88

    Re: VBA - Remove text from named range and table

    Now it's asking for loRowNum haha sorry

  30. #30
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: VBA - Remove text from named range and table

    It is row number variable so:
    Please Login or Register  to view this content.

  31. #31
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: VBA - Remove text from named range and table

    Hi ormerods

    Here are all the Dim Statements for that Code...sorry
    Please Login or Register  to view this content.

+ 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] How to remove a deleted named range completely
    By megaiooo in forum Excel General
    Replies: 8
    Last Post: 08-16-2013, 09:01 PM
  2. Array formulas referencing a named range or named table
    By anrichards22 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-03-2013, 11:59 PM
  3. Remove prepositions in text using named range list
    By Northstjarna in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 05-10-2013, 09:09 AM
  4. Replies: 7
    Last Post: 01-24-2013, 06:55 PM
  5. Copy sheets and remove named range
    By digdug in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-08-2007, 04:41 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