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

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”。

如何解决这个问题?
附言这是我在 vba 上的第一个代码。

最佳答案

您可以在最终结果中对 TRIM()toIndex 空格进行 REPLACE,即

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

从这里举起的例子:http://www.techonthenet.com/excel/formulas/replace.php

所以...
f = Replace (f, " ", "")

关于excel - 删除VBA excel中的空格,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10574000/

10-12 12:20