| 
    
     |  | ▼Porta さん: 
 >最初に表示される日にちは今日の年月日ですが、
 >
 >例えば月のスピンを▽で1にしたくても出来ず、先ず△を使い2に
 >変更して▽で1にスピンしなくてはなりませんが…
 >
 >▽を押せば減数、△は増数という単純な動きは
 >今のコードの一部変更では出来ないものでしょうか。
 
 思いっきり方法を変更してみました。
 
 SpinButtonのイベントは Changeイベントでなく、
 SpinUp, SpinDown イベントを使います。
 
 モジュールレベルの変数 myDateに変更後の日付を格納して、
 年用 SpinButtonが押されたら、 myDate = DateAdd("yyyy",±1, myDate)
 月用 SpinButtonが押されたら、 myDate = DateAdd("m", ±1, myDate)
 日用 SpinButtonが押されたら、 myDate = DateAdd("d", ±1, myDate)
 という方式で、日付を変更しています。
 
 '----------------------------------------  UserForm2
 Option Explicit
 
 Private MaxDate As Date
 Private myDate As Date
 
 Private Sub UserForm_Initialize()
 myDate = Date
 MaxDate = DateAdd("yyyy", 8, myDate)
 SetDate
 Label4.Caption = "年"
 Label5.Caption = "月"
 Label6.Caption = "日"
 End Sub
 
 Private Sub SetDate()
 Dim n As Integer
 Dim colr As Long
 If myDate > MaxDate Then Beep: myDate = MaxDate
 Label1.Caption = Year(myDate)
 Label2.Caption = Month(myDate)
 Label3.Caption = Day(myDate)
 
 n = Weekday(myDate)
 If n = 1 Then colr = vbRed Else colr = vbBlack
 Label3.ForeColor = colr
 End Sub
 
 
 Private Sub SpinButton1_SpinDown()
 myDate = DateAdd("yyyy", 1, myDate)
 SetDate
 End Sub
 
 Private Sub SpinButton1_SpinUp()
 myDate = DateAdd("yyyy", -1, myDate)
 SetDate
 End Sub
 
 Private Sub SpinButton2_SpinDown()
 myDate = DateAdd("m", 1, myDate)
 SetDate
 End Sub
 
 Private Sub SpinButton2_SpinUp()
 myDate = DateAdd("m", -1, myDate)
 SetDate
 End Sub
 
 Private Sub SpinButton3_SpinDown()
 myDate = DateAdd("d", 1, myDate)
 SetDate
 End Sub
 
 Private Sub SpinButton3_SpinUp()
 myDate = DateAdd("d", -1, myDate)
 SetDate
 End Sub
 
 Private Sub CommandButton1_Click()
 Dim r As Range
 Dim c As Range
 Dim m
 
 '      [A6]セルに先頭日付
 Set r = Range("A6", Cells(Rows.Count, "A").End(xlUp))
 m = Application.Match(CLng(myDate), r, 1)
 Set c = r.Item(m, 1)
 If c.Value = myDate Then
 c.Activate
 MsgBox myDate & " 日へジャンプしました", , "セル位置は" & c.Address(0, 0)
 Else
 MsgBox "その年月日はありません", vbExclamation
 End If
 End Sub
 
 |  |