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

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
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,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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