日付の表示を揃える:Excel VBA入門 |
スポンサードリンク | |
Private Sub Worksheet_Change(ByVal Target As Range) Dim c As Range Dim fmt As String If Intersect(Target, Range("A1:A50")) Is Nothing Then Exit Sub For Each c In Intersect(Target, Range("A1:A50")) If IsDate(c.Value) Then If Len(Format(c.Value, "e")) = 1 Then fmt = "[$-411]ggg_0e年" Else fmt = "[$-411]ggge年" End If If Format(c.Value, "m") < 10 Then fmt = fmt & "_0m月" Else fmt = fmt & "m月" End If If Len(Format(c.Value, "d")) < 10 Then fmt = fmt & "_0d日" Else fmt = fmt & "d日" End If c.NumberFormatLocal = fmt & ";@" End If Next c End Sub |
Sub DateFormat_yyyy() '//////////////////////////////////////////////////////////// ' 選択した日付セルの表示形式を空白付の桁合せにする ' 例:2009/ 6/ 3 ' 2009/06/23 ユーザー名 : Fujii ' Dim rng As Range, fmt As String For Each rng In Selection If IsDate(rng.Value) Then fmt = "yyyy/" If Month(rng.Value) > 9 Then fmt = fmt & "m/" Else fmt = fmt & "_0m/" End If If Day(rng.Value) > 9 Then fmt = fmt & "d" Else fmt = fmt & "_0d" End If rng.NumberFormatLocal = fmt End If Next rng End Sub |
スポンサードリンク
PageViewCounter
Since2006/2/27