View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Mike H Mike H is offline
external usenet poster
 
Posts: 11,501
Default Removing unnecessary rows through macro

Hi,

This looks for the value "Header" in e1 and if it finds it deletes blank
rows. Right click your sheet tab, view code and paste this and run it.

Sub marine()
Dim MyRange As Range, MyRange1 As Range
If UCase(Range("E1").Value) < "HEADER" Then Exit Sub
lastrow = Cells(Rows.Count, "E").End(xlUp).Row
Set MyRange = Range("E2:E" & lastrow)
For Each c In MyRange
If IsEmpty(c) Then
If MyRange1 Is Nothing Then
Set MyRange1 = c.EntireRow
Else
Set MyRange1 = Union(MyRange1, c.EntireRow)
End If
End If
Next
If Not MyRange1 Is Nothing Then
MyRange1.Delete
End If
End Sub

Mike

" wrote:

I have data in column E which consists of names. some rows have data
(names) and some does not (blank). I want to delete all rows where
column e has blank cells and where the data = "header".

For instance, lets say the column E looks like this (Range E1:E23)

header


name1
name2


name3

header

name4


name5
name6

header




name7.

The desired output i want is like this (Range E1:E7)

name1
name2
name3
name4
name5
name6
name7

The last row is unknown, we therefore need to identify the last row
first and then run the macro

Can somebody help?