Blogtrottr
Mobile01最新文章
 
[Excel VBA]輸入yyyymmdd直接轉換成日期格式,已有初步程式碼
Nov 11th 2014, 18:11

本身習慣直接輸入yyyymmdd做日期格式,剛開始是用儲存格格式修改,讓它表面像是日期,但後續需求需要使用正式的日期格式,使用google & 本身的想法稍微撰寫了一下VBA,但是其實出現許多BUG,希望版上的神人能幫在下修改一下!

PS:月與日部分希望能維持2位數,9月>09
這部分後來有在格式那邊調整成yyyy/mm/dd,但有時候會自動填0,有時候不會(主要是為了整齊)

已知BUG:
1.選取多個儲存格進行資料變更、刪除會錯誤13,型態不符合。
2.儲存格原始是日期格式,直接輸入日期(yyyymmdd)會產生錯誤6,溢位。

=====程式碼=====
Private Sub Worksheet_Change(ByVal Target As Range)
Dim KeyCells As Range
Dim DteValue As String
Dim YY As String
Dim MM As String
Dim DD As String
Set KeyCells = Range("A:A")
If Not Application.Intersect(KeyCells, Range(Target.Address)) Is Nothing And Len(Target.Cells) = 8 Then
DteValue = Target.Value
YY = Left(DteValue, 4)
MM = Mid(DteValue, 5, 2)
DD = Right(DteValue, 2)
Target.Cells = YY + "/" + MM + "/" + DD
End If
End Sub
=====程式碼=====

This entry passed through the Full-Text RSS service - if this is your content and you're reading it on someone else's site, please read the FAQ at fivefilters.org/content-only/faq.php#publishers.

You are receiving this email because you subscribed to this feed at blogtrottr.com.

If you no longer wish to receive these emails, you can unsubscribe from this feed, or manage all your subscriptions
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 xals2q 的頭像
    xals2q

    2015花千骨線上看tv 2016花千骨 花千骨線上看drama q 花千骨線上看drama 仙俠奇緣之花千骨線上看 花千骨線上看tv543 電視劇花千骨線上看 花千骨線上看第一集

    xals2q 發表在 痞客邦 留言(0) 人氣()