Concatenating a String and an Integer in VBA

Solved
Hugo -  
ccm81 Posted messages 11033 Status Member -
Hello,

When I write:
a = "B" & Str(8)
b = "B" + Str(8)

I get: a -> "B 8" and b -> "B 8"
However, I would like to obtain "B8" without the space.

In my code, I need to generate strings of the form "Bi" where i is an integer.

I don’t understand where that damn space comes from.
Do you have any idea?

3 answers

  1. ccm81 Posted messages 11033 Status Member 2 434
     
    Hello

    if a is of type string then a = "B" & 8 is correct
    Note: you can always remove the space with a = "B" & trim(str(8)), but why make it so complicated
    best wishes
    4
    1. Hugo
       
      a is declared as a string, i is a loop iterator
      a = "B" & i is incorrect and raises a type error

      thank you for trim I'm going to use that.
      0