Trim Cells using VBA in Excel

后端 未结 8 1204
你的背包
你的背包 2020-12-11 03:02

I have what seems like a simple problem with some data in Excel. I have a lot of data with leading spaces pasted from a web table, and I would like to get rid of the initial

8条回答
  •  星月不相逢
    2020-12-11 03:36

    I would try to solve this without VBA. Just select this space and use replace (change to nothing) on that worksheet you're trying to get rid off those spaces.

    If you really want to use VBA I believe you could select first character

    strSpace = left(range("A1").Value,1)
    

    and use replace function in VBA the same way

    Range("A1").Value = Replace(Range("A1").Value, strSpace, "")
    

    or

    for each cell in selection.cells
     cell.value = replace(cell.value, strSpace, "")
    next
    

提交回复
热议问题