Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Viveka Fischer   on Feb 21 In MS Office Category.

  
Question Answered By: Nicholas Wells   on Feb 21

+ isn't the "official" concatenation operator, and indeed it doesn't always
work properly. E.g. the following code fails

Private Sub CommandButton1_Click()
Dim a As Integer: a = 111
Dim b As Integer: b = 222
Dim c As String: c = a + b + "another string"
Range("a1").Value = c
End Sub

The error  is a type mismatch on the c = a + b + "another string"

However, ampersands work  fine:

Private Sub CommandButton1_Click()
Dim a As Integer: a = 111
Dim b As Integer: b = 222
Dim c As String: c = a & b & "another string"
Range("a1").Value = c
End Sub

sets A1 to 111222another string  as you'd expect.

Share: 

 

This Question has 10 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on how to concatenate string variables Or get search suggestion and latest updates.


Tagged: