回答
让我们假设你想在A列
- 转到一个空列摆脱空格的(可以说B)
- 输入
=TRIM(A1)
为B1。 - 向下填充此公式成B.
- 的所有行然后塔B复制到剪贴板,并使用“糊状内容物”,以列B的值(不是式)复制回塔A.
你可以使用内置的TRIM
功能吗?它消除了空白,从传递给它的文本的开头和结尾:
=TRIM(A1)
这个公式会给你从A1单元格文本没有前导或尾随whitepace。
要使用该公式,您需要在原始列旁边插入一列。然后将公式输入到第一个(顶部)空单元格中,将原始列的第一个(顶部)单元格的单元格坐标替换为“A1”,然后按enter键。然后,您可以抓住单元格的右下角(光标将更改为“+”符号),然后将该框向下拖动到新列中的最后一个单元格,以重复列中所有行的公式。
但我怎么究竟做 - 选择列行,然后呢? – Slee
@Slee:我更新了我的答案。如果您对公式不熟悉,Google或Excel的帮助功能可帮助您入门。 –
在您的空格删除请求请注意:
TRIM
只删除字符32,即一个标准的空间。CLEAN
将除去非印刷的空白如回车(字符13)和换行(字符10)CLEAN
不处理非中断空格(字符160),与涉及从数据的一个常见问题网络,为此,你需要一个SUBSTITUTE
功能
你可以做到这一点无论其在整个单元格公式,或更怕疼(和指定的前导空格)与vba
使用公式,您可以结合使用这三个公式来清理整个单元,例如
=TRIM(CLEAN(SUBSTITUTE(A1,CHAR(160)," ")))
。请参阅Ron de Bruins的书写here下面的VBA将使用数组和正则表达式就地替换您的数据,而无需任何工作列和复制粘贴。下面的代码包含使用说明。此代码仅适用于字符串的开头部分,不像公式选项
Sub KillLeadingSpaces() 'Press Alt + F11 to open the Visual Basic Editor (VBE) 'From the Menu, choose Insert-Module. 'Paste the code into the right-hand code window. 'Press Alt + F11 to close the VBE 'In Xl2003 Goto Tools ....Macro .... Macros and double-click KillLeadingSpaces 'In Xl2007/10 Goto Developer .. Macros and double-click KillLeadingSpaces Dim rng1 As Range Dim rngArea As Range Dim lngRow As Long Dim lngCol As Long Dim lngCalc As Long Dim objReg As Object Dim X() On Error Resume Next Set rng1 = Application.InputBox("Select range for the replacement of leading zeros", "User select", Selection.Address, , , , , 8) If rng1 Is Nothing Then Exit Sub On Error GoTo 0 'See Patrick Matthews excellent article on using Regular Expressions with VBA Set objReg = CreateObject("vbscript.regexp") objReg.Pattern = "^[\s|\xA0]+" 'Speed up the code by turning off screenupdating and setting calculation to manual 'Disable any code events that may occur when writing to cells With Application lngCalc = .Calculation .ScreenUpdating = False .Calculation = xlCalculationManual .EnableEvents = False End With 'Test each area in the user selected range 'Non contiguous range areas are common when using SpecialCells to define specific cell types to work on For Each rngArea In rng1.Areas 'The most common outcome is used for the True outcome to optimise code speed If rngArea.Cells.Count > 1 Then 'If there is more than once cell then set the variant array to the dimensions of the range area 'Using Value2 provides a useful speed improvement over Value. On my testing it was 2% on blank cells, up to 10% on non-blanks X = rngArea.Value2 For lngRow = 1 To rngArea.Rows.Count For lngCol = 1 To rngArea.Columns.Count 'replace the leading zeroes X(lngRow, lngCol) = objReg.Replace(X(lngRow, lngCol), vbNullString) Next lngCol Next lngRow 'Dump the updated array sans leading whitepace back over the initial range rngArea.Value2 = X Else 'caters for a single cell range area. No variant array required rngArea.Value = objReg.Replace(rngArea.Value, vbNullString) End If Next rngArea 'cleanup the Application settings With Application .ScreenUpdating = True .Calculation = lngCalc .EnableEvents = True End With Set objReg = Nothing End Sub
- 1. tomcat修剪白色空间
- 2. Excel中的空白单元格
- 3. 修剪mysql中的空白
- 4. 空白单元格的Excel列表
- 5. 正在修剪的XSLT空白元素
- 6. 空白单元格
- 7. 在数据库中插入空的excel单元格作为空白单元格
- 8. 修剪DB2中Char列中的空白空间
- 9. Excel导入返回空白单元格
- 10. 减去空白单元格 - Excel
- 11. Excel函数与空白单元格
- 12. Excel计数非空白单元格
- 13. 以Excel中的间隙形式绘制空白单元格
- 14. 检查excel中的单元格是否为空或空白
- 15. 链接到Excel中的空白单元格时出现空值
- 16. 修剪白色空间和C#
- 17. 在sed中修剪尖括号内的空白空间
- 18. 需要修剪oracle中的空白空间
- 19. Excel VBA - 如何找到空白单元格和从活动单元格到空白单元格的总和
- 20. 防止XmlBeans修剪空白
- 21. Cygwin修剪尾随空白
- 22. 使用PIL修剪空白
- 23. 左修剪空白XSLT 1.0
- 24. 停止NSTokenField修剪空白
- 25. 表格单元格内的Flash影片上的空白空间
- 26. UITableView的空白单元格
- 27. StreamingPathFilter修剪空格
- 28. Python的修剪空白列表中的
- 29. Excel VBA - 清除空白不为空的单元格
- 30. PHP修剪不修剪的空间
在Office 2011中,您必须执行“选择性粘贴”,并确保选择粘贴值。方法略有不同,结果相同。 – peelman
@peelman:Office 2011? –
是... Office 2011 ... http://www.microsoft.com/mac – peelman