'清除所有sheet页中单元格两端的空格
Public Sub trimCell()
Dim sheetCount, columnCount, rowCount, tempRow, tempCol
Dim rng As Range
'Set Worksheet = ThisWorkbook.Sheets("Sheet1")
'Dim columd As Integer
'Dim rowd As Integer
'columd = Worksheet.Range("IV1").End(xlToLeft).Column
'rowd = Worksheet.Range("A65536").End(xlUp).Row
'获取本excel的sheet的数量
sheetCount = ThisWorkbook.Sheets.Count
For i = 1 To sheetCount
ThisWorkbook.Sheets(i).Select
'sheet原始选择的单元格?号和列号
tempRow = Selection.Row
tempCol = Selection.Column
'获取当前数据区域的?号和列号
columnCount = ActiveSheet.UsedRange.Columns.Count
rowCount = ActiveSheet.UsedRange.Rows.Count
'将数据区域置于选择区域
Range(Cells(1, 1), Cells(rowCount, columnCount)).Select
'遍历数据区域每个单元格
For Each rng In Selection
rng.Value = Trim(rng.Value)
Next
'还原单元格选择区域
Cells(tempRow, tempCol).Select
Next
End Sub