selecting certain rows

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a macro that selects rows based on their data.

IE.

x = Application.WorksheetFunction.Match("AIR", Range
("J:J"), 0)
y = Application.WorksheetFunction.Match("AIR", Range
("J:J"), 1)
Rows(x & ":" & y).Copy

This will select and copy all rows containing AIR in
Column J.

When AIR is in the file that I use the macro on, it works
correctly. However, if the file does not contain AIR
(which may be the case), I want the macro to ignore it,
and go to the next part of the macro.

However, it just copies some other rows instead!

Can you help?

Jempie
 
Hi
one way:
Sub foo()
Dim x, y
On Error Resume Next
x = Application.WorksheetFunction.Match("AIR", Range _
("J:J"), 0)
y = Application.WorksheetFunction.Match("AIR", Range _
("J:J"), 1)
If Err.Number = 0 Then
Rows(x & ":" & y).Copy
Else
MsgBox "not found"
End If
On Error GoTo 0
End Sub
 
I saw your example, and thought it might help me with my problem.

Suppose I wanted to select all of the rows which contain the date for
the day before yesterday in row J. How would you modify that formula?

Thanks
DK


Hi
one way:
Sub foo()
Dim x, y
On Error Resume Next
x = Application.WorksheetFunction.Match("AIR", Range _
("J:J"), 0)
y = Application.WorksheetFunction.Match("AIR", Range _
("J:J"), 1)
If Err.Number = 0 Then
Rows(x & ":" & y).Copy
Else
MsgBox "not found"
End If
On Error GoTo 0
End Sub


"If you can't beat them, arrange to have them beaten." ---George Carlin
 
Back
Top