在VBA中选定的单元格上执行修剪功能 [英] Perform trim function on the selected cells in VBA
本文介绍了在VBA中选定的单元格上执行修剪功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
它应该在所选列或选定的单元格上工作
Sub trim()
ActiveCell.FormulaR1C1 == trim(R1C1)
End Sub
解决方案
:
Sub TrimAndFit()
Dim r As Range
With Application.WorksheetFunction
对于每个r在相交(选择,ActiveSheet.UsedRange)
r.Value = .Trim(r.Value)
下一个r
结束
End Sub
这将适用于所有选择 ed单元格。我们使用 Intersect()
来提高成效。
I am trying to figure out if there is a way I could run a simple function (TRIM to remove duplicate space characters) in an Excel macro so it is performed directly on the cell and so I don't have to create an extra column with the function that TRIMs the previous column.
It should work on selected column or just selected cells
Sub trim()
ActiveCell.FormulaR1C1 = "=trim(R1C1)"
End Sub
解决方案
Give this a try:
Sub TrimAndFit()
Dim r As Range
With Application.WorksheetFunction
For Each r In Intersect(Selection, ActiveSheet.UsedRange)
r.Value = .Trim(r.Value)
Next r
End With
End Sub
This will work on all Selected cells. We use Intersect()
to improve performance.
这篇关于在VBA中选定的单元格上执行修剪功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文