Iferror Invalid Procedure

Ruca13

Board Regular
Joined
Oct 13, 2016
Messages
85
Hello folks,

I'm trying to add what's on the left of "/", but sometimes the cell does not contain that character, and I am having trouble handling the error:

Code:
    Dim fbormk as Variant
    fbormk = Left(Cells(ActiveCell.Row, rmks), InStr(1, Cells(ActiveCell.Row, rmks), "/") - 1)
    If IsError(fbormk) = True Then
    fbormk = Cells(ActiveCell.Row, rmks)
    Else
    'fbormk = Left(Cells(ActiveCell.Row, rmks), InStr(1, Cells(ActiveCell.Row, rmks), "/") - 1)
    End If
        mail_body_message = Replace(sup_msg, "^", Cells(ActiveCell.Row, icao) & "/" & fbormk)

Whenever the cell does not contain "/", I get an Invalid Procedure error on the fbormk line.

On the other cases the code runs fine.

Thanks for the help
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
You could make it so that InStr will always find the / by simply adding / to the end of the string it searches.

fbormk = Left(Cells(ActiveCell.Row, rmks), InStr(1, Cells(ActiveCell.Row, rmks) & "/", "/") - 1)

This will elimnate the need to test fbormk for error
because putting the / at the end of the string, when the string doesn't contain a /, it makes the left function return the whole original string
 
Upvote 0

Forum statistics

Threads
1,217,360
Messages
6,136,102
Members
449,991
Latest member
IslandofBDA

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top