Need macro to auto delete as in example

D

doc

Let's say I have a range from A1 to G10 (just an example) and in this
range data is being brought forward from other work sheets. What I
would like to do is delete only the cells to the right of the cell in
column A that is empty (also the cell in column A). Understand that
some cells that need to be deleted will have zeros in them. Also some
of the cells above the ones to be deleted will be blank or have zeros
in them as well. Long story short can a macro be written that deletes
a range of cells if the first cell in the range is either blank or has
s specific entry in it?....Thanks in advance for any help. I have
attached an example xls that explains better than my stumbling wording.

File Attached: http://www.exceltip.com/forum/attachment.php?postid=311091 (example.xls)
 
D

Dave Peterson

Yeah, you could have a macro, but I'm confused at what you want to really do.

Is it look in column A, if it's empty (or 0), then
1. delete that row (entirely)
2. clear the contents of A:G of that row--but don't delete it
3. delete columns A:G of that row and shift cells up (but don't touch H:IV)

I'm gonna guess the first one--delete the row.

Option Explicit
Sub testme01()

Dim myCell As Range
Dim delRng As Range
Dim deleteIt As Boolean

With Worksheets("sheet1")
For Each myCell In .Range("a1:a" & _
.Cells.SpecialCells(xlCellTypeLastCell).Row).Cells
deleteIt = False
If IsEmpty(myCell) Then
deleteIt = True
Else
If IsNumeric(myCell.Value) Then
If myCell.Value = 0 Then
deleteIt = True
End If
End If
End If
If deleteIt = True Then
If delRng Is Nothing Then
Set delRng = myCell
Else
Set delRng = Union(myCell, delRng)
End If
End If
Next myCell
End With

If delRng Is Nothing Then
MsgBox "nothing to be deleted"
Else
delRng.EntireRow.Delete
End If

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top