Invalid Property Value error for Userform - excel

I have tried going through multiple threads to find an answer that I need but not able to sort it out yet.
I have certain combo boxes in my userform and I have a button to upload the details. Once the details are uploaded in my excel sheet, I want the form to clear all the contents and reset to blanks. The data is getting updated perfectly in the excel file, however each time I get an error stating Invalid Property Value. I want to be able to upload the details without getting the error. I have tried setting the combo box style to list, however, it still gives me the same error
Also if the user selects a value in the combo box and later deletes it then the same message is again popped up and the user can't move to another filed until he selects a value from the list. I want the user to be able to delete the entry or select only from the list (that's why I have the match required set to True).
Can someone please guide
PFB the code :
Private Sub CmdUploadDatabaseDetails_Click()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set wb = Workbooks.Open("C:\Users\anup.patil\Desktop\Dashboard
Testing.xlsx")
wb.Activate
IsEntryBlank = CheckIfBlanksDatabase
If IsEntryBlank = True Then
MsgBox "Please fill all the mandatory details"
wb.Close False
cwb.Activate
Me.CBMonth.SetFocus
Exit Sub
End If
Sheets("Database").Select
Range("B1").End(xlDown).Select
Selection.Copy
ActiveCell.Offset(1).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Lastrow = Sheets("Database").Cells(Rows.Count, "A").End(xlUp).Row
Cells(Lastrow + 1, 1).Select
ActiveCell.Value = Me.CBMonth.Value
ActiveCell.Offset(, 2).Value = Me.TBParentCo.Text
ActiveCell.Offset(, 3).Value = Me.TBSubsidaryCo.Text
ActiveCell.Offset(, 4).Value = Me.CBCustomerCat.Text
ActiveCell.Offset(, 5).Value = Me.TBContactName.Text
ActiveCell.Offset(, 6).Value = Me.TBDesignation.Text
ActiveCell.Offset(, 7).Value = Me.TBDept.Text
ActiveCell.Offset(, 8).Value = Me.CBVertical.Text
ActiveCell.Offset(, 9).Value = Me.CBSubVertical.Text
ActiveCell.Offset(, 10).Value = Me.TBOperatingLoc.Text
ActiveCell.Offset(, 11).Value = Me.TBNearbyHKVBr.Text
ActiveCell.Offset(, 12).Value = Me.TBOperatingLocAddr.Text
ActiveCell.Offset(, 13).Value = Me.CBOperatingLocState.Text
ActiveCell.Offset(, 15).Value = Me.CBDecisionMakingUnit.Text
ActiveCell.Offset(, 16).Value = Me.TBHOCentralized.Text
ActiveCell.Offset(, 17).Value = Me.TBMobileNo.Text
ActiveCell.Offset(, 18).Value = Me.TBPhoneNo.Text
ActiveCell.Offset(, 19).Value = Me.TBEmail.Text
ActiveCell.Offset(, 20).Value = Me.CBRelationshipBuild.Text
ActiveCell.Offset(, 21).Value = Me.TBMemberOfAssoc.Text
ActiveCell.Offset(, 22).Value = Me.TBListOfEmpanelled.Text
ActiveCell.Offset(, 23).Value = Me.CBGiftAllowed.Text
ActiveCell.Offset(, 24).Value = Me.CBGiftDeliveryMode.Text
ActiveCell.Offset(, 25).Value = Me.TBSurvPotential.Text
Me.CBMonth.ListIndex = -1
Me.CBMonth.Value = ""
Me.TBParentCo.Value = ""
Me.TBSubsidaryCo.Value = ""
Me.CBCustomerCat.Value = ""
Me.TBContactName.Value = ""
Me.TBDesignation.Value = ""
Me.TBDept.Value = ""
Me.CBVertical.Value = ""
Me.CBSubVertical.Value = ""
Me.TBOperatingLoc.Value = ""
Me.TBNearbyHKVBr.Value = ""
Me.TBOperatingLocAddr.Value = ""
Me.CBOperatingLocState.Value = ""
Me.CBDecisionMakingUnit.Value = ""
Me.TBHOCentralized.Value = ""
Me.TBMobileNo.Value = ""
Me.TBPhoneNo.Value = ""
Me.TBEmail.Value = ""
Me.CBRelationshipBuild.Value = ""
Me.TBMemberOfAssoc.Value = ""
Me.TBListOfEmpanelled.Value = ""
Me.CBGiftAllowed.Value = ""
Me.CBGiftDeliveryMode.Value = ""
Me.TBSurvPotential.Value = ""
Me.CBMonth.SetFocus
wb.Close True
MsgBox "Details uploaded successfully"
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub

Set MatchingRequired to False for the combobox.

Related

Insert userform data into next column on respective rows

I want to add the values from a form to an Excel sheet.
I have the "headers" in column A from A1 down to A20 with A21 a "score" field that runs from B21 to CZ21 that automatically calculates a score based on the values entered above in each respective column.
A1 through 20 has the headers for the questions and I want the values from the form entered initially in B1 through 20 and then C1-20 and so on and so forth.
As an example, the first form response should be entered into rows B1 to B20 with each row having a value. The second form response will be entered into rows C1 to C20 with each row having it's own value.
Column A is a frozen pane.
Private Sub SaveButton_Click()
'Make Sheet2 active
Sheet4.Activate
'Determine empty Row
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
Cells(emptyRow, 2).Value = TextBox1.Value
Cells(emptyRow, 3).Value = Format(Now)
Cells(emptyRow, 4).Value = TextBox3.Value
If CheckBox1.Value = True Then
Cells(emptyRow, 5).Value = CheckBox1
Else
Cells(emptyRow, 5).Value = CheckBox1
End If
If CheckBox2.Value = True Then
Cells(emptyRow, 6).Value = CheckBox2
Else
Cells(emptyRow, 6).Value = CheckBox2
End If
If CheckBox3.Value = True Then
Cells(emptyRow, 7).Value = CheckBox3
Else
Cells(emptyRow, 7).Value = CheckBox3
End If
If CheckBox4.Value = True Then
Cells(emptyRow, 8).Value = CheckBox4
Else
Cells(emptyRow, 8).Value = CheckBox4
End If
If CheckBox9.Value = True Then
Cells(emptyRow, 9).Value = CheckBox9
Else
Cells(emptyRow, 9).Value = CheckBox9
End If
If CheckBox11.Value = True Then
Cells(emptyRow, 10).Value = CheckBox11
Else
Cells(emptyRow, 10).Value = CheckBox11
End If
If CheckBox14.Value = True Then
Cells(emptyRow, 11).Value = CheckBox14
Else
Cells(emptyRow, 11).Value = CheckBox14
End If
If CheckBox16.Value = True Then
Cells(emptyRow, 12).Value = CheckBox16
Else
Cells(emptyRow, 12).Value = CheckBox16
End If
If CheckBox18.Value = True Then
Cells(emptyRow, 13).Value = CheckBox18
Else
Cells(emptyRow, 13).Value = CheckBox18
End If
If CheckBox20.Value = True Then
Cells(emptyRow, 14).Value = CheckBox20
Else
Cells(emptyRow, 14).Value = CheckBox20
End If
If CheckBox22.Value = True Then
Cells(emptyRow, 15).Value = CheckBox22
Else
Cells(emptyRow, 15).Value = CheckBox22
End If
If CheckBox24.Value = True Then
Cells(emptyRow, 16).Value = CheckBox24
Else
Cells(emptyRow, 16).Value = CheckBox24
End If
If CheckBox26.Value = True Then
Cells(emptyRow, 17).Value = CheckBox26
Else
Cells(emptyRow, 17).Value = CheckBox26
End If
If CheckBox27.Value = True Then
Cells(emptyRow, 18).Value = CheckBox27
Else
Cells(emptyRow, 18).Value = CheckBox27
End If
If CheckBox28.Value = True Then
Cells(emptyRow, 19).Value = CheckBox28
Else
Cells(emptyRow, 19).Value = CheckBox28
End If
Cells(emptyRow, 20).Value = TextBox5.Value
Cells(emptyRow, 21).Value = TextBox4.Value
'Clearing data
CheckBox1.Value = "False"
CheckBox2.Value = "False"
CheckBox3.Value = "False"
CheckBox4.Value = "False"
CheckBox9.Value = "False"
CheckBox11.Value = "False"
CheckBox14.Value = "False"
CheckBox16.Value = "False"
CheckBox18.Value = "False"
CheckBox20.Value = "False"
CheckBox22.Value = "False"
CheckBox24.Value = "False"
CheckBox26.Value = "False"
CheckBox27.Value = "False"
CheckBox28.Value = "False"
TextBox1.Value = ""
TextBox3.Value = ""
TextBox4.Value = ""
TextBox5.Value = ""
End Sub
You can do something like this
Private Sub SaveButton_Click()
Dim col as Range
Set col = Sheet4.Range("B1:B20") 'first potential location
'find first unused column
Do While Application.CountA(col) > 0
Set col = col.Offset(0, 1)
Loop
col.cells(1).Value = TextBox1.Value
col.cells(2).Value = Format(Now)
col.cells(3).Value = TextBox3.Value
'etc etc

Maintaining Edit History while editing from userform VBA

I am using a userform which is used for both submitting entries and editing them if needed. I am auto populating the form if a person enters a unique id (Material verification checklist number) with the help of TextBox After Update function
Then the user can change any parameters and press edit button to edit the changes. All these things work fine.
There is a requirement to maintain the edit history of all the changes in a different sheet. I am stuck there. This is how the sheet will look:
I am stuck with the C, D and E columns which should capture what parameters were edited, and their old and new values.
This is my code for the edit function right now:
Sub Edit()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.AutomationSecurity = msoAutomationSecurityLow
Dim id As Range
Set id = Worksheets("Transport Assesment").Range("A:A").Find(what:=frm3.TextBox1.Value, LookIn:=xlValues)
Worksheets("Transport Assesment").Unprotect "Ramu#lt12"
id.Offset(, 1).Value = frm3.TextBox13.Value
id.Offset(, 2).Value = frm3.DTPicker2.Value
id.Offset(, 4).Value = frm3.ComboBox7.Value
id.Offset(, 3).Value = frm3.ComboBox8.Value
id.Offset(, 5).Value = frm3.ComboBox6.Value
id.Offset(, 25).Value = frm3.TextBox15.Value
id.Offset(, 6).Value = frm3.ComboBox1.Value
id.Offset(, 7).Value = frm3.TextBox2.Value
id.Offset(, 8).Value = frm3.ComboBox2.Value
id.Offset(, 9).Value = frm3.TextBox3.Value
id.Offset(, 10).Value = frm3.ComboBox3.Value
id.Offset(, 11).Value = frm3.TextBox4.Value
id.Offset(, 12).Value = frm3.ComboBox4.Value
id.Offset(, 13).Value = frm3.TextBox5.Value
id.Offset(, 14).Value = frm3.ComboBox5.Value
id.Offset(, 15).Value = frm3.TextBox6.Value
id.Offset(, 16).Value = frm3.DTPicker3.Value
id.Offset(, 17).Value = frm3.TextBox14.Value
id.Offset(, 18).Value = frm3.DTPicker4.Value
id.Offset(, 19).Value = frm3.TextBox9.Value
id.Offset(, 20).Value = frm3.DTPicker1.Value
id.Offset(, 26).Value = frm3.TextBox16.Value
Worksheets("Transport Assesment").Protect "Ramu#lt12"
ThisWorkbook.Save
End Sub
Please guide me on how should I capture the parameters changed, and their old and new values. Thanks
Suggest using a separate sub to handle comparing the values and updating the tracking info where there's a difference:
'globals for tracking any changes
Dim oldValues, newValues, titles
Sub Edit()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Application.AutomationSecurity = msoAutomationSecurityLow
Dim id As Range
oldValues = ""
newValues = ""
titles = ""
Set id = Worksheets("Transport Assesment").Range("A:A").Find( _
what:=frm3.TextBox1.Value, LookIn:=xlValues)
If Not id Is Nothing Then
Worksheets("Transport Assesment").Unprotect "Ramu#lt12"
LogChanges id.Offset(, 1), frm3.TextBox13.Value
LogChanges id.Offset(, 2), frm3.DTPicker2.Value
LogChanges id.Offset(, 4), frm3.ComboBox7.Value
LogChanges id.Offset(, 3), frm3.ComboBox8.Value
LogChanges id.Offset(, 5), frm3.ComboBox6.Value
'etc etc for rest of cells
If Len(titles) > 0 Then
'have changes - update the tracking sheet
End If
Worksheets("Transport Assesment").Protect "Ramu#lt12"
Else
MsgBox "No match found!"
End If
ThisWorkbook.Save
End Sub
'compare form value with existing: log any change and update cell if required
Sub LogChanges(c As Range, vNew)
With c
sep = IIf(Len(titles) > 0, ";", "") 'need a separator?
If .Value <> vNew Then
'track the changes
titles = titles & sep & .Parent.Cells(1, .Column).Value 'column titles in Row1
oldValues = oldValues & sep & ValueOrBlank(.Value) 'track old value
newValues = newValues & sep & ValueOrBlank(vNew) 'track new value
.Value = vNew 'update the cell
End If
End With
End Sub
Function ValueOrBlank(v)
ValueOrBlank = IIf(Len(v)>0, v, "[blank]")
End Function

Excel VBA - Runtime error 438 : Object doesn't support this property or method

I'm new to VBA and I have the following code.
I want to sum in the variable SumDef the values of all the textboxes in a frame of a userform, if the textbox is not void.
But I get
runtime error 438 : Object doesn't support this property or method
Private Sub CommandButton2_Click()
'PROBLEEEEEM
Dim SumDef As Integer
Dim txt As Control
SumDef = 0
For Each txt In Me.Frame3.Controls
If TypeName(txt) = "TextBox" And IsNumeric(txt.Value) = True Then
SumDef = SumDef + CInt(txt.Text)
End If
Next txt
If TextBox2.Value <> vbNullString And CInt(TextBox2.Text) <= SumDef Then
cell2.Offset(, 7).Value = TextBox2.Text
cell2.Offset(, 19).Value = TextBox3.Text
cell2.Offset(, 8).Value = TextBox4.Text
cell2.Offset(, 9).Value = TextBox5.Text
cell2.Offset(, 10).Value = TextBox6.Text
cell2.Offset(, 11).Value = TextBox7.Text
cell2.Offset(, 12).Value = TextBox8.Text
cell2.Offset(, 13).Value = TextBox9.Text
cell2.Offset(, 14).Value = TextBox10.Text
cell2.Offset(, 15).Value = TextBox11.Text
cell2.Offset(, 16).Value = TextBox12.Text
cell2.Offset(, 17).Value = TextBox13.Text
cell2.Offset(, 18).Value = TextBox14.Text
MsgBox "Bac enregistré avec succes", vbInformation, "ENR FAB 07"
Me.CommandButton3.Enabled = True
Me.CommandButton2.Enabled = False
Else
MsgBox "Nombre de gants défauts est invalide", vbExclamation, "ENR FAB 07"
TextBox2.Value = vbNullString
End If
End Sub
Nest your If statement like this instead as it's trying to evaluate the .Value on all controls otherwise, and not all controls have a .Value property:
If TypeName(txt) = "TextBox" Then
If IsNumeric(txt.Value) = True Then
SumDef = SumDef + CInt(txt.Text)
End If
End If

Data validation in user form

I have a userform for entering the receiving data by the storekeepers, I want to set some mandatory fields for filling in. They are the username, part number and stored location of received file.
I am using the data of my "ref" worksheet for adding items to my combo boxes. and I forced combo box to don't accept any item out of that list. (by using field property "matchrequired" to true).
I have 4 command buttons, done for saving and closing, "add item" for adding a new item to current release note, new release note, which clear the R/N data and would ask for it again, and finally close, which closes the form.
My question is how can I force VBA to check is there any data in the "USER", "P/N" and "Location", and if at least these three field have data, then data entry be possible.
I also want to the code to be able for checking the entry of QTY field and just accepts number (between 1 and 5000 for instance).
Everything is ok with DONE button, but for the two ("add item" and "new release note") stupid errors returns. after msg box showing up the data clears, the combo's items will lost or returns error and so...
I am using "addcmbo" for adding items to combo controls. (Just for user when I am putting that here, the value duplicates in the combo index, and also after message box, the items of this control remains).
If you find any "not good practice" approaches, let me know please.
Sub addcmbo()
Application.ScreenUpdating = False
Sheet2.Activate
' A/C data update
For i = 2 To WorksheetFunction.CountA(Range("b:b"))
If Sheets("Ref").Cells(i, 2) <> "" Then
RCVNG.cmbac.AddItem (Cells(i, 2))
End If
Next
' W/B data update
For i = 2 To WorksheetFunction.CountA(Range("h:h"))
If Sheets("Ref").Cells(i, 8) <> "" Then
RCVNG.Cmbwb.AddItem (Cells(i, 8))
End If
Next
' w/C data update
For i = 2 To WorksheetFunction.CountA(Range("i:i"))
If Sheets("Ref").Cells(i, 9) <> "" Then
RCVNG.Cmbwc.AddItem (Cells(i, 9))
End If
Next
' P/# data update
For i = 2 To WorksheetFunction.CountA(Range("j:j"))
If Sheets("Ref").Cells(i, 10) <> "" Then
RCVNG.Cmbpn.AddItem (Cells(i, 10))
End If
Next
Sheet1.Activate
Application.ScreenUpdating = True
End Sub
Private Sub btnCncl_Click()
Unload Me
End Sub
Private Sub btnadditem_Click()
' Form fields Clear
cmbac.Clear
Cmbwb.Clear
Cmbwc.Clear
Cmbpn.Clear
' cmbac.Value = ""
' Cmbwb.Value = ""
' Cmbwc.Value = ""
' Cmbpn.Value = ""
Txtqty.Value = ""
txtSN.Value = ""
Txtloc.Value = ""
cmnt.Value = ""
' Data entry sufficiency check
If cmbuser = "" Or Cmbpn = "" Or Txtloc = "" Then
MsgBox "Please Fill Required Fields " & Chr(10) & " * User" & Chr(10) & " * Part #" & Chr(10) & " * Location" & Chr(10) & " before Save!"
Call addcmbo
Else:
' Data Entry
Sheet1.Activate
Dim oNewRow As ListRow
ActiveSheet.Cells(1, 3).Select
Set oNewRow = Selection.ListObject.ListRows.Add(AlwaysInsert:=True)
oNewRow.Range.Cells(1, 6).Value = DTPicker.Value
oNewRow.Range.Cells(1, 7).Value = txtrn.Value
oNewRow.Range.Cells(1, 14).Value = cmbuser.Value
oNewRow.Range.Cells(1, 8).Value = cmbac.Value
oNewRow.Range.Cells(1, 10).Value = Cmbwb.Value
oNewRow.Range.Cells(1, 9).Value = Cmbwc.Value
oNewRow.Range.Cells(1, 11).Value = Cmbpn.Value
oNewRow.Range.Cells(1, 12).Value = Txtqty.Value
oNewRow.Range.Cells(1, 13).Value = txtSN.Value
oNewRow.Range.Cells(1, 15).Value = Txtloc.Value
oNewRow.Range.Cells(1, 16).Value = cmnt.Value
End If
End Sub
Private Sub btndone_Click()
' Data entry sufficiency check
If cmbuser = "" Or Cmbpn = "" Or Txtloc = "" Then
MsgBox "Please Fill Required Fields " & Chr(10) & " * User" & Chr(10) & " * Part #" & Chr(10) & " * Location" & Chr(10) & " before Save!"
Else:
' Data Entry
Sheet1.Activate
ActiveSheet.Cells(1, 3).Select
Set oNewRow = Selection.ListObject.ListRows.Add(AlwaysInsert:=True)
oNewRow.Range.Cells(1, 6).Value = DTPicker.Value
oNewRow.Range.Cells(1, 7).Value = txtrn.Value
oNewRow.Range.Cells(1, 14).Value = cmbuser.Value
oNewRow.Range.Cells(1, 8).Value = cmbac.Value
oNewRow.Range.Cells(1, 10).Value = Cmbwb.Value
oNewRow.Range.Cells(1, 9).Value = Cmbwc.Value
oNewRow.Range.Cells(1, 11).Value = Cmbpn.Value
oNewRow.Range.Cells(1, 12).Value = Txtqty.Value
oNewRow.Range.Cells(1, 13).Value = txtSN.Value
oNewRow.Range.Cells(1, 15).Value = Txtloc.Value
oNewRow.Range.Cells(1, 16).Value = cmnt.Value
Unload Me
End If
End Sub
Private Sub btnnewrn_Click()
Dim oNewRow As ListRow
' Form fields Clear
txtrn.Value = ""
cmbac.Clear
Cmbwb.Clear
Cmbwc.Clear
Cmbpn.Clear
cmbac.Value = ""
Cmbwb.Value = ""
Cmbwc.Value = ""
Cmbpn.Value = ""
Txtqty.Value = ""
txtSN.Value = ""
Txtloc.Value = ""
cmnt.Value = ""
' Data entry sufficiency check
If cmbuser = "" Or Cmbpn = "" Or Txtloc = "" Then
MsgBox "Please Fill Required Fields " & Chr(10) & " * User" & Chr(10) & " * Part #" & Chr(10) & " * Location" & Chr(10) & " before Save!"
Call addcmbo
Else:
' Data Entry
Sheet1.Activate
ActiveSheet.Cells(1, 3).Select
Set oNewRow = Selection.ListObject.ListRows.Add(AlwaysInsert:=True)
oNewRow.Range.Cells(1, 6).Value = DTPicker.Value
oNewRow.Range.Cells(1, 7).Value = txtrn.Value
oNewRow.Range.Cells(1, 14).Value = cmbuser.Value
oNewRow.Range.Cells(1, 8).Value = cmbac.Value
oNewRow.Range.Cells(1, 10).Value = Cmbwb.Value
oNewRow.Range.Cells(1, 9).Value = Cmbwc.Value
oNewRow.Range.Cells(1, 11).Value = Cmbpn.Value
oNewRow.Range.Cells(1, 12).Value = Txtqty.Value
oNewRow.Range.Cells(1, 13).Value = txtSN.Value
oNewRow.Range.Cells(1, 15).Value = Txtloc.Value
oNewRow.Range.Cells(1, 16).Value = cmnt.Value
End If
End Sub
Private Sub lblpn_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim pn As String
Application.ScreenUpdating = False
Sheet2.Activate
emptyRow = WorksheetFunction.CountA(Range("j:j")) + 1
pn = inputbox("Type In new ''P/#'' please", "Add NEW P/#")
Cells(emptyRow, 10).Value = pn
RCVNG.Cmbpn.AddItem pn
End Sub
Private Sub lblTeam_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Dim t As String
Application.ScreenUpdating = False
Sheet2.Activate
emptyRow = WorksheetFunction.CountA(Range("c:c")) + 1
t = inputbox("Type type Your Name Please", "Add name of NEW or Missing team member")
Cells(emptyRow, 3).Value = t
RCVNG.cmbuser.AddItem t
End Sub
Private Sub UserForm_Initialize()
Application.ScreenUpdating = False
Sheet2.Activate
DTPicker.SetFocus
DTPicker.Value = Date
' empty fields
shipreceive.Value = ""
txtrn.Value = ""
cmbuser.Clear
cmbac.Clear
Cmbwb.Clear
Cmbwc.Clear
Cmbpn.Clear
Txtqty.Value = ""
txtSN.Value = ""
Txtloc.Value = ""
cmnt.Value = ""
' Combo fields add item
Call addcmbo
' User data update
Application.ScreenUpdating = False
Sheet2.Activate
For i = 2 To WorksheetFunction.CountA(Range("c:c"))
If Sheets("Ref").Cells(i, 3) <> "" Then
RCVNG.cmbuser.AddItem (Cells(i, 3))
End If
Next
Sheet1.Activate
Application.ScreenUpdating = True
End Sub
Thanks a lot, I will appreciate your help

ListBox not populating

I am a beginner using VBA in Excel. I am trying to come up with a user form that looks like this. I have all the coding in, but when I launch it from a command button in Excel, the ListBox does not populate. When I try to enter in numbers and click "submit" I get "Run-time error '424':Object required". When I click debug, it takes me to the line
Cells(emptyRow, 1).Value = dotwListBox.Value
I am not sure what is going on. Any help would be appreciated!! Here is my code:
Private Sub cancel_Click()
Unload Me
End Sub
Private Sub clear_Click()
Call UserForm1_Initialize
End Sub
Private Sub submit_Click()
Dim emptyRow As Long
'Make Sheet3 active
Sheet3.Activate
'Determine emptyRow
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
'Transfer information
Cells(emptyRow, 1).Value = dotwListBox.Value
Cells(emptyRow, 2).Value = t235tocbTextBox.Value
Cells(emptyRow, 3).Value = t235codbTextBox.Value
Cells(emptyRow, 4).Value = apiphbTextBox.Value
Cells(emptyRow, 5).Value = apiturbiditybTextBox.Value
Cells(emptyRow, 6).Value = apitocbTextBox.Value
Cells(emptyRow, 7).Value = apicodbTextBox.Value
Cells(emptyRow, 8).Value = apibodbTextBox.Value
Cells(emptyRow, 9).Value = longbaydobTextBox.Value
Cells(emptyRow, 10).Value = asudobTextBox.Value
Cells(emptyRow, 11).Value = rasmlssbTextBox.Value
Cells(emptyRow, 12).Value = clarifierturbiditybTextBox.Value
Cells(emptyRow, 13).Value = clarifierphbTextBox.Value
Cells(emptyRow, 14).Value = clarifiernh3bTextBox.Value
Cells(emptyRow, 15).Value = clarifierno3bTextBox.Value
Cells(emptyRow, 16).Value = clarifierenterococcibTextBox.Value
Cells(emptyRow, 17).Value = clarifierphosphorusbTextBox.Value
End Sub
Private Sub UserForm1_Initialize()
'Empty t235tocbTextBox
t235tocb.Value = ""
'Empty t235codTextBox
t235codb.Value = ""
'Fill dotwListBox
With dotwListBox
.AddItem "Monday"
.AddItem "Tuesday"
.AddItem "Wednesday"
.AddItem "Thursday"
.AddItem "Friday"
End With
'Empty apiphbTextBox
aphiphb.Value = "1"
'Empty apiturbiditybTextBox
apiturbidityb.Value = ""
'Empty apitocbTextBox
apitocb.Value = ""
'Empty apicodbTextBox
apicodb.Value = ""
'Empty apibodbTextBox
apibodb.Value = ""
'Empty longbaydobTextBox
longbaydob.Value = ""
'Empty asudobTextBox
asudob.Value = ""
'Empty rasmlssbTextBox
rasmlssb.Value = ""
'Empty clarifierturbiditybTextBox
clarifierturbidityb.Value = ""
'Empty clarifierphbTextBox
clarifierphb.Value = ""
'Empty clarifiernh3bTextBox
clarifiernh3b.Value = ""
'Empty clarifierno3bTextBox
clarifierno3b.Value = ""
'Empty clarifierenterococcibTextBox
clarifierenterococcib.Value = ""
'Empty clarifierphosphorusTextBox
clarifierphosphorusb.Value = ""
End Sub
There can be two reasons:
Your ListBox MultiSelect property is set to 1 (fmMultiSelectMulti) or 2 (fmMultiSelectExtented)
In this case its Value property will be always Null
Your ListBox has no item selected
even if its MultiSelect property is set to 0 (fmMultiSelectSingle) its Value property will return Null if no item is selected
In this case set a check with its ListIndex property, like follows
If dotwListBox.ListIndex <> -1 Then Cells(emptyRow, 1).Value = dotwListBox.Value
Since -1 is the value returned by ListIndex property when no item is selected

Resources