+ Reply to Thread
Results 1 to 9 of 9

How to stop a table from being deleted when setting a range?

  1. #1
    Registered User
    Join Date
    05-29-2015
    Location
    Croatia
    MS-Off Ver
    2013
    Posts
    19

    How to stop a table from being deleted when setting a range?

    Let's say that cells A1 and B1 contain some values and cells A2 and B2 are empty, but a table is inserted in them.

    If we run this code:

    Please Login or Register  to view this content.
    the table in cells A2 and B2 disappears.

    How should this code look like if I want to keep the table?

  2. #2
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: How to stop a table from being deleted when setting a range?

    What do you mean by table disappears?

    Can you upload a sample workbook to see what content actually you have on sheet1? And what is the full code?
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  3. #3
    Registered User
    Join Date
    05-29-2015
    Location
    Croatia
    MS-Off Ver
    2013
    Posts
    19

    Re: How to stop a table from being deleted when setting a range?

    The problematic part of code is part of a bigger project I'm working on and I can't paste the whole code here.
    I've excerpted this line as an example and the problem persists when only this line is present, meaning that the problem is not due to other parts of the code.

    The workbook with the example is in the attachment. Notice how the table in the cells A2 and B2 disappears after clicking the CommandButton1 button.
    Attached Files Attached Files

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How to stop a table from being deleted when setting a range?

    What do you actually want to do?

    Insert values in the table?
    If posting code please use code tags, see here.

  5. #5
    Registered User
    Join Date
    05-29-2015
    Location
    Croatia
    MS-Off Ver
    2013
    Posts
    19

    Re: How to stop a table from being deleted when setting a range?

    Yes, I want to insert values in the table.

  6. #6
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: How to stop a table from being deleted when setting a range?

    Maybe you can try something like this.....
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    05-29-2015
    Location
    Croatia
    MS-Off Ver
    2013
    Posts
    19

    Re: How to stop a table from being deleted when setting a range?

    Quote Originally Posted by sktneer View Post
    Maybe you can try something like this.....
    Please Login or Register  to view this content.
    No, this doesn't work because it resizes the table (adds another row). The table needs to keep its original dimensions. After running this code, the table is in range A2:B3 instead of the original range A2:B2.
    It partially worked because the table wasn't deleted after running the code.
    Last edited by Mutak; 07-12-2016 at 08:13 AM.

  8. #8
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: How to stop a table from being deleted when setting a range?

    Hi,

    You could write one cell at a time. If your table has more columns, you can write all bar one column using an array and then write the last one. As long as you do not overwrite the entire table at once, it will remain in place.
    Last edited by xlnitwit; 07-12-2016 at 09:03 AM. Reason: Clarity
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  9. #9
    Registered User
    Join Date
    05-29-2015
    Location
    Croatia
    MS-Off Ver
    2013
    Posts
    19

    Re: How to stop a table from being deleted when setting a range?

    Quote Originally Posted by xlnitwit View Post
    Hi,

    You could write one cell at a time. If your table has more columns, you can write all bar one column using an array and then write the last one. As long as you do not overwrite the entire table at once, it will remain in place.
    The range is much larger and this method would be too difficult for me to code. However, I added a line to sktneer's code:

    Please Login or Register  to view this content.
    And after this the problem seems to be solved. Thanks everyone.

+ 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. Active X Controls Stop working even after .exd files were deleted
    By rmeckm2 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-06-2015, 11:33 AM
  2. Replies: 0
    Last Post: 11-19-2012, 03:55 AM
  3. Stop running till the columns are deleted!
    By casperzero in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-29-2012, 02:19 AM
  4. Replies: 6
    Last Post: 06-12-2012, 04:36 PM
  5. Formulas change when column/row is deleted... how can i stop that?
    By RNiner in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 11-11-2006, 06:03 PM
  6. How to stop CommandButtons being deleted as pictures in code??
    By Corey in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-15-2006, 07:25 AM
  7. Setting Range in Pivot Table
    By Dhiraj in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 08-14-2005, 09:05 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