+ Reply to Thread
Results 1 to 2 of 2

Delete a single row in a table except the last.

  1. #1
    Registered User
    Join Date
    02-11-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2016
    Posts
    1

    Delete a single row in a table except the last.

    Hi Guys,

    This is my first post. I am experienced with Excel but an amateur with VBA. I have code which deletes a table row (containing the active cell) that works perfectly except that it also deletes the last row in the table and the table disappears. I would like to insert some additional code to prevent a row from being deleted if it is the last row. Thanks for your help in advance. Here's the code I am using -

    Application.ScreenUpdating = False

    Dim rng As Range

    On Error Resume Next
    With Selection.Cells(1)
    Set rng = Intersect(.EntireRow, ActiveCell.ListObject.DataBodyRange)
    On Error GoTo 0
    If rng Is Nothing Then
    MsgBox "Please select a valid table cell.", vbCritical
    Else
    rng.Delete xlShiftUp
    End If
    End With

    Application.ScreenUpdating = True

    End Sub

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Delete a single row in a table except the last.

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

    this works for me

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

+ 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] Help on VBA code to delete a row in more than one table from a single command button
    By grahamlees in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-24-2017, 05:46 AM
  2. [SOLVED] Code to delete a single character from a single cell
    By axtryo in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 03-03-2017, 01:08 AM
  3. [SOLVED] Making a chart from a single table no pivot table
    By sportfan in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 09-30-2015, 02:15 AM
  4. Find and delete single character
    By KH_GS in forum Excel General
    Replies: 13
    Last Post: 01-23-2014, 04:26 AM
  5. delete single spaces
    By jomili in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-24-2011, 11:39 AM
  6. Delete single zero in cell
    By rosef in forum Excel General
    Replies: 1
    Last Post: 11-25-2009, 02:21 PM
  7. delete single spaces
    By Mark R in forum Excel General
    Replies: 4
    Last Post: 04-26-2006, 07:15 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