+ Reply to Thread
Results 1 to 4 of 4

Clearing Row of Data

  1. #1
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,438

    Clearing Row of Data

    I am using the following VBA code to clear a row when the user clicks on a cell in colum "X". The intent is to clear the single row of data when it is no longer needed. However, this code doesn't just clear the row of data, it actually removes the row and moves all rows below it, up one.

    I need a code modification that will only erase the data in the cells of the row ... not delete the entire row from the tab.

    Your assistance is appreciated. Thank you.

    Sub DeleteRowWithContents()
    '========================================================================
    ' DELETES ALL ROWS FROM X DOWNWARDS WITH THE WORDs "Record Only" IN COLUMN D
    '========================================================================
    Last = Cells(Rows.Count, "X").End(xlUp).Row
    For i = Last To 1 Step -1
    If (Cells(i, "X").Value) = "X" Then
    'Cells(i, "A").EntireRow.ClearContents ' USE THIS TO CLEAR CONTENTS BUT NOT DELETE ROW
    Cells(i, "X").EntireRow.Delete
    End If
    Next i
    End Sub

  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
    48,434

    Re: Clearing Row of Data

    Remove the line:

    Please Login or Register  to view this content.

    Does what it says on the tin. Uncomment the line above it.


    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 Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,438

    Re: Clearing Row of Data

    Man oh man ... can anyone say "Working late and being tired makes a person look foolish ?" I'm embarrassed but thankful. Have a great day.
    Last edited by Logit; 01-06-2013 at 08:40 AM.

  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
    48,434

    Re: Clearing Row of Data

    You're welcome. Thanks for the rep.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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