所以我在excel中使用了一个带有VBA的API,我从程序中得到的输出在数字中间放了一个双空格,比如123456 7891011。我目前的解决方案是,
With ws.Range("J2:J98")
.Formula = "=LEFT(I2,6)"
End With
With ws.Range("K2:K98")
.Formula = "=RIGHT(I2,7)"
End With
With ws.Range("L2:L98")
.Formula = "=CONCATENATE(J2,K2)"
.Value = .Value
.NumberFormat = "0"
End With把J和K藏起来。
我的问题是:有没有一种方法可以在不使用单元格保存公式的情况下做到这一点?
下面是我用来提取我想要修改的内容的代码
ActiveSheet.Cells(k, 9) = Trim(autECLSession.autECLPS.GetText(4, 24, 15))而解决方案是
With ws.Range("L2:L98")
.Formula = "=Substitute(I2,"" "", """")"
.Value = .Value
.NumberFormat = "0"
End With我的问题的一个修正是,我甚至需要输出来命中Cell吗,或者我可以在它之前运行替代吗?
发布于 2014-03-04 00:43:32
您可以做的一件事是使用替换,而不是使用左右并连接它们:
=SUBSTITUTE(I2;" ";"")这将减少所需的隐藏列的数量。
不确定您到底想要做什么,但您可以用选定/目标区域上的循环替换原始内容。则不需要公式,并且原始范围将被新值替换。
发布于 2014-03-04 00:45:05
Activecell = Range("J2")
for x=1 to 97
if instr(1, activecell, " ") > 0 then ' test do see if a double space is present in the activecell
activecell = replace(activecell, " ", "") ' if so, remove it
else
end if
next xhttps://stackoverflow.com/questions/22152094
复制相似问题