Remove whitespace in VBA excel

后端 未结 2 1814
离开以前
离开以前 2020-12-21 08:16

I have some code for move text from cell to cell

Dim startIndex As Integer
Dim toIndex As Integer
Dim f As String
Dim g As String

For startIndex = 50 To 60          


        
相关标签:
2条回答
  • 2020-12-21 08:37

    You should be using
    CStr
    not
    Str

    Then no workaround is needed for removing an unncessary space

    ie

     f = "F" & CStr(toIndex)
     g = "G" & CStr(startIndex)  
    

    From Excel help for Str

    When numbers are converted to strings, a leading space is always reserved for the sign of number.

    0 讨论(0)
  • 2020-12-21 08:52

    You could TRIM() the toIndex or REPLACE spaces in the end result, i.e.

    Replace ("alphabet", "a", "e")  'would return "elphebet"
    

    example lifted from here: http://www.techonthenet.com/excel/formulas/replace.php

    So...

    f = Replace (f, " ", "")
    
    0 讨论(0)
提交回复
热议问题