- 帖子
- 2035
- 主題
- 24
- 精華
- 0
- 積分
- 2031
- 點名
- 0
- 作業系統
- Win7
- 軟體版本
- Office2010
- 閱讀權限
- 100
- 性別
- 男
- 註冊時間
- 2012-3-22
- 最後登錄
- 2024-2-1
|
25#
發表於 2013-6-7 08:03
| 只看該作者
回復 23# Hsieh
回復 21# GBKEE
我將 GBKEE 版大的模組、加上 Hsieh 版大提供的 Function,
兩者組合後還蠻實用的:- Sub Ex_日期數值3()
- Dim i As Long, xl_Year As Variant
- With Range("B1:B" & [A1].End(xlDown).Row)
- For i = 1 To .Count
- .Cells(i) = ChDate(.Cells(i).Offset(, -1))
- If .Cells(i) <> "" Then .Cells(i).Offset(, 1) = CEDate(.Cells(i))
- Next
- ' .Offset(,-1): 左移 1 欄 (B -> A欄); Resize(,3): 從A欄起擴充為三欄 (A、B、C 三欄)
- ' .Cells(1) = "2012年10月12日" (B 欄), .Cells(1).Offset(, 1) = "2012/10/12" (C 欄)
- ' .Offset(, -1).Resize(, 3).Sort Key1:=.Cells(1), Order1:=xlAscending, Header:=xlNo
- .Offset(, -1).Resize(, 3).Sort Key1:=.Cells(1).Offset(, 1), Order1:=xlAscending, Header:=xlNo
- End With
- End Sub
複製代碼- Function ChDate(DateStr As String)
- ' DateStr必須是包含"中華民國年月日"的字串
- Dim Mystr As String, s%
-
- s = InStr(DateStr, "中華民國") + 4
- If s = 4 Then ChDate = "": Exit Function
- Mystr = Mid(DateStr, s, InStr(s, DateStr, "日") - s + 1)
- ChDate = Replace(Mystr, Val(Mystr) & "年", Val(Mystr) + 1911 & "年")
- End Function
- Function CEDate(DateStr As String) ' 「C.E.」是「Common Era」的縮寫,意為「公元」
- CEDate = CDate(DateStr)
- End Function
複製代碼 謝謝兩位版大的鼎力幫忙。 |
|