Actually, I forgot something ....
Private Sub BtnDelete_Click()
Dim fRow As Long,WS as Worksheet, rngHitCell as Range
Set WS = Workbooks("Whatever").Worksheets("Whatever")
Set rngHitCell = WS.Columns(1).Find(What:=TxtMan.Value, _
After:=Cells(5000, 1), LookIn:=xlFormulas, _
LookAT:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, _
SearchFormat:=False)
If rngHitCell is Nothing Then
MsgBox "Value not found"
Else
If rngHitCell.Row > 5000 then
WS.Rows(rngHitCell.Row).Delete
Else
Msgbox "Value found before Row 5000"
End If
End If
End Sub
"INTP56" wrote:
> To make it not care what is active, use variables
>
> Private Sub BtnDelete_Click()
> Dim fRow As Long,WS as Worksheet, rngHitCell as Range
> Set WS = Workbooks("Whatever").Worksheets("Whatever")
>
> Set rngHitCell = WS.Columns(1).Find(What:=TxtMan.Value, _
> After:=Cells(5000, 1), LookIn:=xlFormulas, _
> LookAT:=xlWhole, SearchOrder:=xlByRows, _
> SearchDirection:=xlNext, MatchCase:=False, _
> SearchFormat:=False)
>
> If rngHitCell is Nothing Then
> MsgBox "Value not found"
> Else
> WS.Rows(rngHitCell.Row).Delete
> End If
>
> End Sub
>
> "Mekinnik" wrote:
>
> > Does the worksheet have to active for this code to work?
> >
> > Private Sub BtnDelete_Click()
> > Dim fRow As Long
> >
> > On Error GoTo ender
> > fRow = Columns(1).Find(What:=TxtMan.Value, _
> > After:=Cells(5000, 1), LookIn:=xlFormulas, _
> > LookAT:=xlWhole, SearchOrder:=xlByRows, _
> > SearchDirection:=xlNext, MatchCase:=False, _
> > SearchFormat:=False).Row
> > Rows(fRow).Delete
> > Exit Sub
> >
> > ender:
> > MsgBox "Value not found"
> > End Sub
> >
> > Because if it does not then it doesn't work. Right now it requires it to be
> > and I would like to knwo how to make so it doesn't need the sheet to be
> > active?
|