返回列表 上一主題 發帖

[發問] 儲存格字串長度大於255

回復 15# a77261988
  1. Sub nn()
  2. Dim A As Range, i%, s%
  3. If Application.CountA(Selection.EntireColumn) = 0 Then Exit Sub '避免欄位無資料
  4. For Each A In Selection.EntireColumn.SpecialCells(xlCellTypeConstants)
  5. i = 0: s = 0: A = Application.WorksheetFunction.Substitute(A, Chr(10), "") '取消換行符號
  6. Do Until InStr(Mid(A, i + 1), "-") = 0
  7.   i = InStr(i + 1, A, "-")
  8.   s = s + 1
  9.   If s Mod 3 = 0 Then A = Application.WorksheetFunction.Replace(A, i, 1, "-" & Chr(10))
  10. Loop
  11. Next
  12. Selection.EntireColumn.AutoFit
  13. End Sub
複製代碼
學海無涯_不恥下問

TOP

        靜思自在 : 太陽光大、父母恩大、君子量大,小人氣大。
返回列表 上一主題