Hi
This is a code I have for a userform. In it, I want to create a worksheet that has a button to display a userform with input boxes for the date (DD-MM-YYYY), time(HH:MM), and pH(0-14) of some data:
Option Explicit
Sub Commandbutton_Add()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")
'find first empty row in database
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
'check for a Name number
If Trim(Me.Textbox_Date.Value) = "" Then
Me.Textbox_Date.SetFocus
MsgBox "Please complete the form"
Exit Sub
End If
'copy the data to the database
ws.Cells(iRow, 1).Value = Me.Textbox_Date.Value
ws.Cells(iRow, 2).Value = Me.Textbox_Time.Value
ws.Cells(iRow, 3).Value = Me.Textbox_pH.Value
MsgBox "Data added", vbOKOnly + vbInformation, "Data Added"
'clear the data
Me.Textbox_Date.Value = ""
Me.Textbox_Time.Value = ""
Me.Textbox_pH.Value = ""
Me.Textbox_Date.SetFocus
End Sub
Sub Commandbutton_Close()
Unload Me
End Sub
Private Sub Date_Box_Click()
End Sub
then under Forms - UserForm1 I have the Entry Form popup box that has an Add Data and Close Form command button with six boxes (3 are labels and 3 are textboxes). The Error I am getting is saying "Cannot run the macro 'blah.xlsm!UserForm1'. The macro may not be available in this workbook or all macros may be disabled. Can someone let me know what's up? Thanks
This is a code I have for a userform. In it, I want to create a worksheet that has a button to display a userform with input boxes for the date (DD-MM-YYYY), time(HH:MM), and pH(0-14) of some data:
Option Explicit
Sub Commandbutton_Add()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")
'find first empty row in database
iRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
'check for a Name number
If Trim(Me.Textbox_Date.Value) = "" Then
Me.Textbox_Date.SetFocus
MsgBox "Please complete the form"
Exit Sub
End If
'copy the data to the database
ws.Cells(iRow, 1).Value = Me.Textbox_Date.Value
ws.Cells(iRow, 2).Value = Me.Textbox_Time.Value
ws.Cells(iRow, 3).Value = Me.Textbox_pH.Value
MsgBox "Data added", vbOKOnly + vbInformation, "Data Added"
'clear the data
Me.Textbox_Date.Value = ""
Me.Textbox_Time.Value = ""
Me.Textbox_pH.Value = ""
Me.Textbox_Date.SetFocus
End Sub
Sub Commandbutton_Close()
Unload Me
End Sub
Private Sub Date_Box_Click()
End Sub
then under Forms - UserForm1 I have the Entry Form popup box that has an Add Data and Close Form command button with six boxes (3 are labels and 3 are textboxes). The Error I am getting is saying "Cannot run the macro 'blah.xlsm!UserForm1'. The macro may not be available in this workbook or all macros may be disabled. Can someone let me know what's up? Thanks