返回列表 上一主題 發帖

[發問] 請問如何將內容有中華民國日期的字眼抓出來轉成西元日期?

回復 1# freeffly
  1. Sub Ex()
  2.     Dim R As Range, xl_Year As Integer
  3.     Set R = [A1]
  4.     Do While R <> ""
  5.         If InStr(R, "中華民國") Then
  6.         'InStr 函數 傳回在某字串中一字串的最先出現位置,此位置為 Variant (Long)。
  7.             xl_Year = Mid(R, InStr(R, "中華民國") + 4, InStr(R, "年") - InStr(R, "中華民國") - 4) '年度
  8.             R = Replace(R, xl_Year, xl_Year + 1911)
  9.             R = Replace(R, "中華民國", "")
  10.         End If
  11.         Set R = R.Offset(1)
  12.         Loop
  13. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

本帖最後由 GBKEE 於 2013-5-30 17:48 編輯

回復 3# freeffly
  1. Sub Ex()
  2.     Dim i  As Long, xl_Year As Variant
  3.     With Range("B1:B" & [A1].End(xlDown).Row)
  4.         .Cells = "=MID(RC[-1],10,10)"
  5.         .Value = .Value
  6.         .Replace "發", ""
  7.         For i = 1 To .Count
  8.             xl_Year = Split(.Cells(i), "年")
  9.             xl_Year(0) = xl_Year(0) + 1911 & "年"
  10.             .Cells(i) = Trim(Join(xl_Year, ""))
  11.         Next
  12.     End With
  13. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 7# freeffly
  1. Sub Ex_日期數值()
  2.     Dim i  As Long, xl_Year As Variant
  3.     With Range("B1:B" & [A1].End(xlDown).Row)
  4.         .Cells = "=MID(RC[-1],10,10)"
  5.         .Value = .Value
  6.         .Replace "發", ""
  7.         .Cells(1).Select
  8.         For i = 1 To .Count
  9.             xl_Year = Split(.Cells(i), "年")
  10.             xl_Year(0) = xl_Year(0) + 1911 & "年"
  11.             .Cells(i) = Trim(Join(xl_Year, ""))
  12.             DoEvents
  13.             Application.SendKeys "{F2}"
  14.             Application.SendKeys "~"
  15.             DoEvents
  16.         Next
  17.         .Cells(1).Select
  18.         .Cells.Sort Key1:=.Cells(1), Order1:=xlAscending, Header:=xlNo
  19.     End With
  20. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 13# c_c_lai
  1. Sub Ex_日期數值()
  2.     Dim i  As Long, xl_Year As Variant
  3.     With Range("B1:B" & [A1].End(xlDown).Row)
  4.         .Cells = "=MID(RC[-1],10,10)"
  5.         .Value = .Value
  6.         .Replace "發", ""
  7.         For i = 1 To .Count
  8.             xl_Year = Split(.Cells(i), "年")
  9.             xl_Year(0) = xl_Year(0) + 1911 & "年"
  10.             .Cells(i) = Trim(Join(xl_Year, ""))
  11.         Next
  12.         .Cells.Replace "年", "/", xlPart
  13.         .Cells.Replace "月", "/"
  14.         .Cells.Replace "日", ""
  15.         .Cells.Sort Key1:=.Cells(1), Order1:=xlAscending, Header:=xlNo
  16.     End With
  17. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

回復 20# c_c_lai
  1. Sub Ex_日期數值()
  2.     Dim i  As Long, xl_Year As Variant
  3.     With Range("B1:B" & [A1].End(xlDown).Row)
  4.         .Cells = "=MID(RC[-1],10,10)"
  5.         .Value = .Value
  6.         .Replace "發", ""
  7.         For i = 1 To .Count
  8.             xl_Year = Split(.Cells(i), "年")
  9.             xl_Year(0) = xl_Year(0) + 1911 & "年"
  10.             .Cells(i) = Trim(Join(xl_Year, ""))
  11.         Next
  12.         .Cells.Replace "年", "/", xlPart
  13.         .Cells.Replace "月", "/"
  14.         .Cells.Replace "日", ""
  15.         .Offset(, -1).Resize(, 2).Sort Key1:=.Cells(1), Order1:=xlAscending, Header:=xlNo
  16.         .Offset(, -1).Resize(, 2).Select         'Offset(, -1) ->左移1欄 'Resize(, 2)  ->擴充為兩欄
  17.         '.Cells.Sort Key1:=.Cells(1), Order1:=xlAscending, Header:=xlNo
  18.     End With
  19. End Sub
複製代碼
感恩的心......(在麻辣家族討論區.用心學習會有進步的)
但資源無限,後援有限,  一天1元的贊助,人人有能力.

TOP

        靜思自在 : 好事要提得起,是非要放得下,成就別人即是成就自己。
返回列表 上一主題