|
▼かみちゃん さん:
'Date
ws1.Cells(i, 5).Value = Me.TextBox1.Value
の箇所を変えるといいましたが
Calendar1.Value = Date
および
Private Sub Calendar1_Click()
TextBox1.Value = Calendar1.Value
End Sub
を追加するというのが正確でした。
躍るように動作しております。
ありがとうございました。
(標準モジュール)
Option Explicit
Public i As Long
Public ws1 As Worksheet
Sub Sample()
If Not Application.Intersect(Range("B3:B104"), ActiveCell) Is Nothing Then
Set ws1 = Worksheets("history")
i = ws1.Range("B65536").End(xlUp).Row + 1
If i < 5 Then
i = 5
End If
With ActiveCell
ws1.Cells(i, 2).Resize(, 3).Value = Array(.Offset(, -1).Value, .Value, .Offset(, 3).Value)
ws1.Cells(i, 2).Offset(, 7).Value = .Offset(, 5).Value
End With
UserForm1.Show
Else
MsgBox "Programのいずれかをアクティブにしてください。"
End If
End Sub
(ユーザーフォーム)
Option Explicit
Private Sub UserForm_Initialize()
Calendar1.Value = Date
' カレンダーの日付をセルにセットする
Dim i As Integer
Me.TextBox1.Value = Date
With Me.ComboBox1
For i = 1 To 24
.AddItem i
Next
End With
With Me.ComboBox2
For i = 0 To 45 Step 15
.AddItem i
Next
End With
With Me.ComboBox3
For i = 1 To 24
.AddItem i
Next
End With
With Me.ComboBox4
For i = 0 To 45 Step 15
.AddItem i
Next
End With
End Sub
Private Sub Calendar1_Click()
TextBox1.Value = Calendar1.Value
' カレンダーの日付をセルにセットする
End Sub
Private Sub CommandButton1_Click()
Dim From_Str As String
Dim To_Str As String
Dim Hours As Double
If Me.ComboBox1.Value <> "" And Me.ComboBox2.Value <> "" Then
From_Str = Me.ComboBox1.Value & ":" & Me.ComboBox2.Value
End If
If Me.ComboBox3.Value <> "" And Me.ComboBox4.Value <> "" Then
To_Str = Me.ComboBox3.Value & ":" & Me.ComboBox4.Value
End If
If From_Str <> "" And To_Str <> "" Then
Hours = (CDate(To_Str) - CDate(From_Str)) * 24
'Date
ws1.Cells(i, 5).Value = Me.TextBox1.Value
'Time(From)
ws1.Cells(i, 6).Value = CDate(From_Str)
'Time(To)
ws1.Cells(i, 7).Value = CDate(To_Str)
'Hours
ws1.Cells(i, 8).Value = (CDate(To_Str) - CDate(From_Str)) * 24
'Place
ws1.Cells(i, 10).Value = Me.TextBox2.Value
'Notese
ws1.Cells(i, 11).Value = Me.TextBox3.Value
End If
Unload UserForm1
End Sub
Private Sub UserForm_Deactivate()
Unload UserForm1
End Sub
|
|