Dim i As Integer
i = Int((8 - 2 + 1) * Rnd + 2)
Dim rg As String
Dim con As String
con = Str(i)
rg = "B" & con
MsgBox (rg)
This returns "B 4" not "B4 anyone know the issue
To eliminate spaces at the beginning and at the end of the String, use String#trim() method. And then use your mytext. replaceAll("( )+", " ") .
Python String strip() function will remove leading and trailing whitespaces. If you want to remove only leading or trailing spaces, use lstrip() or rstrip() function instead.
Using re. sub() or split() + join() method to remove extra spaces between words in Python.
Use Cstr(i)
rather than Str(i)
. Cstr
does not add a space.
From the Help page for Str()
When numbers are converted to strings, a leading space is always reserved for the sign of number. If number is positive, the returned string contains a leading space and the plus sign is implied.
Str()
leaves space for the sign.
As Excel has implicit conversion, you can use rg = "B" & i
and get the range you want
Use format() function ...
con = format(i)
rg = "B" & con
MsgBox (rg)
Use the Trim function to remove leading space as under:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim i As Integer
i = Int((8 - 2 + 1) * Rnd + 2)
Dim rg As String
Dim con As String
con = Str(i)
rg = "B" & Trim(con)
MsgBox (rg)
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With