TRIM function/remove spaces from cells using VBA

前端 未结 3 671
名媛妹妹
名媛妹妹 2021-02-08 05:43

I am using the code below to trim some \"blank cells\" that contain a space. The thing is it takes too much time, as is looping to every cell. What I want is to remove the spac

3条回答
  •  感情败类
    2021-02-08 06:06

    Do it on the whole range at once using the array version of Excel's Trim:

    myRange.Value = Application.Trim(myRange.Value)
    

    Using the only variables visible in your code, it would be:

    With Range(Cells(1,1), Cells(ScenarioTableLastRow, ScenarioTableLastColumn))
         .Value = Application.Trim(.Value)
    End With
    

提交回复
热议问题