View Single Post
  #6   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,

There' no reason this won't run as an addin but it worksheet code and works
on the active sheet. To check if your in the correct workbook you will need
to call another routine to check for those values and pass a variable back to
the sub try this. The sub now call a sub which must go in a general module
and pases the variable 'rightbook'

Sub marine()
MySearch
If Not RightBook Then Exit Sub
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

Public RightBook As Boolean
Sub MySearch()
RightBook = False
For Each ws In Worksheets
ws.Select
With ActiveSheet.UsedRange
Set c1 = .Find("Manipulation", LookIn:=xlValues)
Set c2 = .Find("Reversal", LookIn:=xlValues)
Set c3 = .Find("Movement Control", LookIn:=xlValues)
End With
Next
On Error GoTo 100
If c1 < "" And c2 < "" And c3 < "" Then RightBook = True
RightBook = True
100:
End Sub

Mike


" wrote:

Super !!!

I want to clarify a doubt. I am going to put this code in a blank .xla
file and create a template (Addin) and give a shortcut key. I am
guessing that when I press the shortcut key, it will just run the
macro irrespective of which excel file is opened. Is that right?

If yes, is it possible to do a check before running the macro?

For instance, find three unique words in the entire excel file
"Manipulation" "Reversal" and "Movement Control". If these three words
are present, only then run the macro. (This is to check if the correct
file is open)

Thanks again

On Oct 14, 3:34 pm, Mike H wrote:
I misunderstood,

Try this instead

Sub marine()