回覆列表
-
1 # 我熱了下快太胖我陪
-
2 # 已經過期了
1、以去除下列資料單元格內空格為例。
3、從Excel視窗切換到VBA視窗,
4、插入模組,複製貼上以下程式碼:
Sub Clear_Space()
Dim rng As Range
Set rng = Selection
For Each rng In Selection
rng.Replace What:=" ", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Next
End Sub
7、然後就完成了。
檢查一個單元格有多少空格,事實上就是在一個字串查詢一個字元出現的次數。做個自定義的函式:Function xTime(X, S As String) As Integer Dim I%, J% I = Len(X) For J = 1 To I If Mid(X, J, 1) = S Then xTime = xTime + 1 NextEnd Function然後用xtime(單元格," ")來呼叫行了。