本文介绍了在VBA Excel中删除空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码可以将文本从一个单元格移动到另一个单元格

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 Step 2
toIndex = Str(startIndex + 1)
f = "F" & Str(toIndex)
g = "G" & Str(startIndex)
Range(f).Value = Range(g).Value
Range(g).Value = ""
Next startIndex

但是变量f的值为"F 51"而不是"F51".

But variable f has "F 51" value instead of "F51".

如何解决这个问题?p.s.这是我在vba上的第一个代码.

How solve this problem ?p.s. It's my first code on vba.

推荐答案

您可以在最终结果中TRIM() toIndexREPLACE空格,即

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

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

示例从此处提出: http://www.techonthenet.com/excel/formulas/replace.php

所以...

f = Replace (f, " ", "")

这篇关于在VBA Excel中删除空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 03:52