回答
讓我們假設你想在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