+ Reply to Thread
Results 1 to 3 of 3

Thread: Delete Data with code

  1. #1
    Registered User
    Join Date
    08-15-2006
    Posts
    42

    Delete Data with code

    I have a “names” sheet that I update or delete names from (all in a single column). I have a macro that I run after I delete or add a new name, will copy and paste the names to “another sheet” (for tracking purposes) and than sorts the list of names.

    When I run the macro, it all works well. However, is my only issue when I delete a name, that other data that was associated stays behind (I have to delete myself afterwards).

    Is there a piece of code that could check if names column is blank, delete data from previous column, same row?

    For example:
    Macro copies names to D6:D165. Every name in the list has data associated to it in the previous columns/rows (A6:A165, B6:B165 and C6:165). Once the macro runs, have the code check if there are any empty cells in D6:D165, if so, delete any data to only the columns/rows that correspond to the empty cells.

    If D130 is empty, delete A130, B130 and C130.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & read 2007
    Posts
    15,979
    Hello Rz6657,

    Try this macro. You change the starting row which is set to 6, if you need to. The last row in column "D" is found automatically.
    Sub DeleteEmptyRows()
    
      Dim LastRow As Long
      Dim R As Long
      Dim StartRow As Long
      
        StartRow = 6
        LastRow = Cells(Rows.Count, "D").End(xlUp).Row
        
          For R = LastRow To StartRow Step -1
            If Cells(R, "D").Value = "" Then
               Cells(R, "D").EntireRow.Delete
            End If
          Next R
        
    End Sub
    Sincerely,
    Leith Ross

  3. #3
    Registered User
    Join Date
    08-15-2006
    Posts
    42
    Thanks for the reply. I have a question about your code. I have formulas in the other consecutive columns. Will your code delete my formulas also, since it says delete entire row.. ? (the only cells that don't have formulas are columns A, B C...

    Thanks.

+ 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.2.0