Error cannot be detected by Excel?

luissuarez

New Member
Joined
Mar 17, 2016
Messages
4
Code:
Sub DetermineErrMsg()


Dim selr As Integer


selr = Selection.Row


On Error Resume Next


Range("c" & selr) = Range("a" & selr) + Range("b" & selr)


If Err.Number <> 0 Then 'There is an error
    If Err.Number = 13 Then
    MsgBox "Please type a number in the box"
    End If
Else: MsgBox "There is no error"




End If


End Sub


http://s24.postimg.org/ncebpkbwz/excelvba.jpg


Hello everyone! I don't know why excel cannot detect an error when I put texts in Cell A4 and B4. It just returns the combined texts in Cell C4. However, an error can be found when I put a number in Cell A3 and texts in Cell B3. Thanks for your help in advance.
 

Some videos you may like

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
47,926
Office Version
  1. 365
Platform
  1. Windows
Welcome to the MrExcel board!

vba can treat "+" like an addition sign or it can treat it like an "&" meaning to concatenate two strings.

If you provide it with 2 numbers it knows to add.
If you provide it with 2 strings it knows to concatenate.
If you provide it with one of each, it is unable to decide what you were trying to do. Hence the error on your middle row and not the other two rows.
 
Last edited:

Watch MrExcel Video

Forum statistics

Threads
1,122,233
Messages
5,594,964
Members
413,955
Latest member
FalcoDaz

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
Top