Option Explicit
Private Sub Workbook_Open()
Application.Visible = False
MsgBox "On the form that appears next..." & vbNewLine & _
vbNewLine & _
"1) Scroll down and select your reading" & vbNewLine & _
"2) Select an appropriate time" & vbNewLine & _
"3) Write any notes" & vbNewLine & _
"4) Click ENTER", , "Entering Blood Glucose Levels"
UserForm1.Show False
End Sub
Option Explicit
Sub ShowForm()
Application.Visible = False
UserForm1.Show False
End Sub
Private Sub RemoveFromMenu()
On Error Resume Next
With Application.CommandBars("Cell")
.Controls("Hide Book").Delete
End With
End Sub
Option Explicit
Private Sub UserForm_Initialize()
With UserForm1
.Caption = "Select your reading and time then click ENTER"
.Height = 338
.Width = 232
.Top = 60
.Left = 180
End With
With ListBox1
.Height = 304
.Width = 40
.Top = 7
.Left = 7
End With
With ListBox2
.Height = 133
.Width = 166
.Top = 7
.Left = 54
End With
With Label1
.Height = 20
.Width = 166
.Top = 177
.Left = 54
End With
With TextBox1
.Height = 35
.Width = 166
.Top = 200
.Left = 54
End With
With CommandButton1
.Height = 30
.Width = 82
.Top = 245
.Left = 55
End With
With CommandButton2
.Height = 30
.Width = 82
.Top = 245
.Left = 138
End With
With CommandButton3
.Height = 34
.Width = 166
.Top = 275
.Left = 54
End With
DoEvents
End Sub
Private Sub UserForm_Activate()
Dim MyList(250), N&
With ListBox1
.ControlTipText = "Blood glucose reading in mmol/L"
.Font.Size = 8
.ColumnWidths = 10
For N = 0 To 250
MyList(N) = (N + 10) / 10
Next
.List = MyList
DoEvents
End With
With ListBox2
.ControlTipText = "NOTE: It is recommended that readings be taken 2 hours after meals, " & _
"if your ''after'' time differs from that, use ''notes''"
.AddItem "On waking / fasting"
.AddItem "Before breakfast"
.AddItem "After breakfast"
.AddItem "Before morning snack"
.AddItem "After morning snack"
.AddItem "Before midday meal"
.AddItem "After midday meal"
.AddItem "Before afternoon snack"
.AddItem "After afternoon snack"
.AddItem "Before evening meal"
.AddItem "After evening meal"
.AddItem "Before late-night snack"
.AddItem "After late-night snack"
DoEvents
End With
[A1] = "Reading (mmol/L)"
[B1] = "Time entered"
[C1] = "Date"
[D1] = "Reading relative to meal"
[E1] = "Notes"
[F1] = "Days Average"
ActiveWindow.FreezePanes = True
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then CommandButton3_Click
End Sub
Private Sub CommandButton1_Click()
Dim N&, ViewIt As Range
If ListBox1 = Empty Or ListBox2 = Empty Then
Exit Sub
End If
With [A65536].End(xlUp)
If .Offset(0, 2) = Date Then
N = 1
Else
N = 2
End If
.Offset(N, 0) = ListBox1
If .Offset(N, 0) = Empty Then Exit Sub
.Offset(N, 1) = Format(Time, "hh:mm ampm")
.Offset(N, 2) = Format(Date, "dd mmm yy")
.Offset(N, 3) = ListBox2
.Offset(N, 4) = TextBox1
If .Offset(N - 1, 0) = Empty Then
.Offset(N, 5) = .Offset(N, 0)
Else
.Offset(N, 5) = Format(WorksheetFunction.Average(.CurrentRegion.Columns(1)), "##.0")
.Offset(N - 1, 5).ClearContents
End If
On Error Resume Next
Application.Goto .Offset(-6, 0).End(xlUp), Scroll:=True
End With
Cells.Columns.AutoFit
ListBox1 = Empty
ListBox2 = Empty
TextBox1 = Empty
End Sub
Private Sub CommandButton2_Click()
Run "RemoveFromMenu"
With Application.CommandBars("Cell")
.Controls.Add(Type:=msoControlButton). _
Caption = "Hide Book"
.Controls("Hide Book"). _
OnAction = "ShowForm"
End With
Application.Visible = True
Unload Me
End Sub
Private Sub CommandButton3_Click()
Run "RemoveFromMenu"
ActiveWorkbook.Save
Unload Me
Application.Quit
End Sub
|