ひとつのセルの文字列を変換して、右隣のセルに書き出す。
Sub sample()
Dim t As String
Dim i As Long
t = ActiveCell.Text
t = Replace(t, ".", "")
For i = Len(t) - 1 To 3 Step -2
t = WorksheetFunction.Replace(t, i, 0, ":")
Next i
ActiveCell.Offset(0, 1).Value = t
End Sub
選択範囲の文字列を置換して、右に書き出す。
Sub sample2()
Dim t As String
Dim i As Long
Dim rng As Range
For Each rng In Selection
t = rng.Text
t = Replace(t, ".", "")
For i = Len(t) - 1 To 3 Step -2
t = WorksheetFunction.Replace(t, i, 0, ":")
Next i
rng.Offset(0, 1).Value = t
Next
End Sub
んで、逆。
Sub sample3()
Dim t As String
Dim i As Long
Dim rng As Range
For Each rng In Selection
t = rng.Text
t = Replace(t, ":", "")
For i = Len(t) - 3 To 3 Step -4
t = WorksheetFunction.Replace(t, i, 0, ".")
Next i
rng.Offset(0, 1).Value = t
Next
End Sub