Userform

elliott10

New Member
Joined
Jan 16, 2020
Messages
23
Office Version
  1. 365
Platform
  1. MacOS
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
 

Some videos you may like

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

CountTepes

Active Member
Joined
Nov 8, 2010
Messages
252
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Assuming that macros are enabled.

Do you have a userform.show to open up your userform?


If not, create an activeX button on your spreadsheet and in the CommandButton1_click() event, Just have the UserForm1.Show command
 

Watch MrExcel Video

Forum statistics

Threads
1,122,319
Messages
5,595,465
Members
413,992
Latest member
CSEGUIN1973

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top