ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   "On Error" help required (https://www.excelbanter.com/excel-programming/370973-error-help-required.html)

Thyagaraj

"On Error" help required
 
Dear Friends,

In the code given below if there is no error then also the msg box is
displayed.

Any help please.

Sub Macro1()
Dim Thyag
On Error GoTo Thyagaraj_Not_Found

Cells.Find(What:="Thyagaraj", After:=ActiveCell,
LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False).Activate

With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid


Thyagaraj_Not_Found:

'Selection.Font.Bold = True
Thyag = MsgBox("Thyagaraj not found")
End With
End Sub


Thanks in Advance

Thyagaraj


Muhammed Rafeek M

"On Error" help required
 
add:
Exit Sub

see below what i modified your code:
Sub Macro1()
Dim Thyag
On Error GoTo Thyagaraj_Not_Found

Cells.Find(What:="Thyagaraj", After:=ActiveCell,
LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False).Activate

With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
exit sub

Thyagaraj_Not_Found:

'Selection.Font.Bold = True
Thyag = MsgBox("Thyagaraj not found")
End With
End Sub


"Thyagaraj" wrote:

Dear Friends,

In the code given below if there is no error then also the msg box is
displayed.

Any help please.

Sub Macro1()
Dim Thyag
On Error GoTo Thyagaraj_Not_Found

Cells.Find(What:="Thyagaraj", After:=ActiveCell,
LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False).Activate

With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid


Thyagaraj_Not_Found:

'Selection.Font.Bold = True
Thyag = MsgBox("Thyagaraj not found")
End With
End Sub


Thanks in Advance

Thyagaraj



Jean-Yves[_2_]

"On Error" help required
 
Hi,

You need to terminate the normal sub before the error handling part by
mentionning Exit sub

Sub Macro1()
On Error GoTo Thyagaraj_Not_Found
.........
Exit sub
Thyagaraj_Not_Found :
........
End sub

Sub Macro1()
Dim Thyag
On Error GoTo Thyagaraj_Not_Found

Cells.Find(What:="Thyagaraj", After:=ActiveCell,
LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False).Activate

With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid
End with
Exit Sub
Thyagaraj_Not_Found:
Thyag = MsgBox("Thyagaraj not found")
End Sub

Regards

JY

"Thyagaraj" wrote in message
oups.com...
Dear Friends,

In the code given below if there is no error then also the msg box is
displayed.

Any help please.

Sub Macro1()
Dim Thyag
On Error GoTo Thyagaraj_Not_Found

Cells.Find(What:="Thyagaraj", After:=ActiveCell,
LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:= _
False).Activate

With Selection.Interior
.ColorIndex = 6
.Pattern = xlSolid


Thyagaraj_Not_Found:

'Selection.Font.Bold = True
Thyag = MsgBox("Thyagaraj not found")
End With
End Sub


Thanks in Advance

Thyagaraj




Nile_Hef[_2_]

"On Error" help required
 
You need an 'Exit Sub' before the start of your 'Thyagaraj_Not_Found: '
error-handling code. Otherwise the code runs all the way to 'End Sub', line
by line, including the lines in your error handler.

Personally, I would insert a label for the 'Exit' code, so that the
error-handler (and any other exit point in your code) can resume at a block
of code containing any 'cleanup' routines you use at the end of the procedu


ExitSub:
[cleanups - erase arrays, set objects = Nothing etc.]
Exit Sub

ErrThyagaraj_Not_Found:
[Error-Handling code]
Resume ExitSub

End Sub

Thyagaraj

"On Error" help required
 

Nile_Hef wrote:
You need an 'Exit Sub' before the start of your 'Thyagaraj_Not_Found: '
error-handling code. Otherwise the code runs all the way to 'End Sub', line
by line, including the lines in your error handler.

Personally, I would insert a label for the 'Exit' code, so that the
error-handler (and any other exit point in your code) can resume at a block
of code containing any 'cleanup' routines you use at the end of the procedu


ExitSub:
[cleanups - erase arrays, set objects = Nothing etc.]
Exit Sub

ErrThyagaraj_Not_Found:
[Error-Handling code]
Resume ExitSub

End Sub



Thanks for all of U



All times are GMT +1. The time now is 10:38 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com