ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Errors (https://www.excelbanter.com/excel-programming/335984-errors.html)

johncassell[_14_]

Errors
 

Hello, I am not too familiar with errors in my code and was hoping for
some help with this please.

I have a control box linked to a stock spreadsheet. After I update this
box(Which is for the stock number), the label next to it will update
with the stock item description. My code does a vlookup for this
value:

Public Sub BinNumber1_AfterUpdate()
Description1 = (WorksheetFunction.VLookup(BinNumber1.Value,
Worksheets("Current Stock").Range("A:B"), 2, False))
End Sub

This works fine if a valid stock number is entered but if someone
enters a bogus number I would like my msgbox to appear saying "Bad
stock number blah blah.." instead of VB opening for debugging.

Thanks in advance for any help.

John


--
johncassell
------------------------------------------------------------------------
johncassell's Profile: http://www.excelforum.com/member.php...o&userid=25016
View this thread: http://www.excelforum.com/showthread...hreadid=391660


STEVE BELL

Errors
 
I usually use code that does a countif, than if it eguals 0 I send a message
to the user.

If WorksheetFunction.Countif(Worksheets("Current Stock").Range("A:B"),
BinNumber1)= 0 then
Msgbox "Bin Number Invalid"
exit sub
Else
'''' your code here
End if

--
steveB

Remove "AYN" from email to respond
"johncassell"
wrote in message
...

Hello, I am not too familiar with errors in my code and was hoping for
some help with this please.

I have a control box linked to a stock spreadsheet. After I update this
box(Which is for the stock number), the label next to it will update
with the stock item description. My code does a vlookup for this
value:

Public Sub BinNumber1_AfterUpdate()
Description1 = (WorksheetFunction.VLookup(BinNumber1.Value,
Worksheets("Current Stock").Range("A:B"), 2, False))
End Sub

This works fine if a valid stock number is entered but if someone
enters a bogus number I would like my msgbox to appear saying "Bad
stock number blah blah.." instead of VB opening for debugging.

Thanks in advance for any help.

John


--
johncassell
------------------------------------------------------------------------
johncassell's Profile:
http://www.excelforum.com/member.php...o&userid=25016
View this thread: http://www.excelforum.com/showthread...hreadid=391660




johncassell[_16_]

Errors
 

I would never have thought of that in a million years, thanks a lot
steve.


--
johncassell
------------------------------------------------------------------------
johncassell's Profile: http://www.excelforum.com/member.php...o&userid=25016
View this thread: http://www.excelforum.com/showthread...hreadid=391660


STEVE BELL

Errors
 
John,

You're very welcome!!!

Just another tid-bit I picked up from this ng...

--
steveB

Remove "AYN" from email to respond
"johncassell"
wrote in message
...

I would never have thought of that in a million years, thanks a lot
steve.


--
johncassell
------------------------------------------------------------------------
johncassell's Profile:
http://www.excelforum.com/member.php...o&userid=25016
View this thread: http://www.excelforum.com/showthread...hreadid=391660





All times are GMT +1. The time now is 05:50 PM.

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