I have a VBA code in which I have to loop through a certain range and fill it using some concatenation but my VBA code is adding undesired blank spaces. For example, let's assume the following example:
code = "NV"
ac = "Curncy"
With wsNew
Set rng = .Range(Cells(2, 2), Cells(2, 2).End(xlDown))
For Each r In rng
If r.Value = 17 Or r.Value = 18 Or r.Value = 19 Then
r.Offset(, 1) = code + r.Offset(, -1).Value + Str(Right(r.Value, 1)) + " " + Str(r.Value) + _
" " + ac
Else
r.Offset(, 1) = code + r.Offset(, -1).Value + Str(Right(r.Value, 1)) + _
" " + ac
End If
Next r
End With
For the first cell (r
variable in the example), I have r.Value = 18
and r.offset(,-1).Value = U
and I was expecting to obtain a value of NVU8 18 Curncy
for my r.Offset(, 1)
. Instead, the code is adding spaces and I get NVU 8 18 Curncy
with one space between U and 8 (to be removed) and 2 spaces between 8 and 18 instead of just one.