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.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
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:
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,279
Members
449,075
Latest member
staticfluids

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