Removing unnecessary rows through macro
I misunderstood,
Try this instead
Sub marine()
Dim MyColumn As String
Dim MyRange As Range, MyRange1 As Range
lastrow = Cells(Rows.Count, "E").End(xlUp).Row
Set MyRange = Range("E1:E" & lastrow)
For Each c In MyRange
If IsEmpty(c) Or UCase(c.Value) = "HEADER" 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:
Thanks for the speedy reply. It gives me result as
header
name1
name2
name3
header
name4
name5
name6
header
name7
I want it as
name1
name2
name3
name4
name5
name6
name7
I also want to delete rows where it says "header"
I tried to modify the code by change the line If IsEmpty(c) to If
IsEmpty(c) Or c.Value = "header" Then but it does not work. I don't
know much programming. Can you help further?
On Oct 14, 3:07 pm, Mike H wrote:
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?- Hide quoted text -
- Show quoted text -
|