Data validation in user form - excel

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

Related

Combobox not showing correct number of rows

I have an Excel (365) spreadsheet with two Comboboxes - Combobox1 and Combobox2 both are used to list the same data for different purposes on different tabs. My problem is that although I have changed listrows in both to the same number (20) only Combobox2 shows 20 rows. Combobox1 only shows the previous number of rows (15) although set to display 20. Anyone know how to get it to behave properly?
EDIT I have solved my origional problem but I would however be interested in using VBA to automatically update both listfillrange and listrows when a new row of data is added. I do have a macro that I use to add new data to my data table that could be adapted to also update listfillrange and listrows
Sub add_to_table_sa_3()
'Written by Keith Cooper 27/10/2021
Dim NewRow As Integer
NewRow = Worksheets("input").Range("E1").Value + 1
If Worksheets("input").Range("F1").Value <> 0 Then
MsgBox "There are errors. No data has been added!", vbOKOnly, "Warning!"
Exit Sub
End If
Worksheets("Data").Cells(NewRow, 1).Value = Worksheets("input").Range("B3").Value
Worksheets("Data").Cells(NewRow, 2).Value = Worksheets("input").Range("B4").Value
Worksheets("Data").Cells(NewRow, 3).Value = Worksheets("input").Range("B5").Value
Worksheets("Data").Cells(NewRow, 4).Value = Worksheets("input").Range("B6").Value
Worksheets("Data").Cells(NewRow, 5).Value = Worksheets("input").Range("B7").Value
Worksheets("Data").Cells(NewRow, 6).Value = Worksheets("input").Range("B8").Value
Worksheets("Data").Cells(NewRow, 7).Value = Worksheets("input").Range("B9").Value
Worksheets("Data").Cells(NewRow, 8).Value = Worksheets("input").Range("B10").Value
Worksheets("Data").Cells(NewRow, 9).Value = Worksheets("input").Range("B11").Value
Worksheets("Data").Cells(NewRow, 10).Value = Worksheets("input").Range("B12").Value
Worksheets("Data").Cells(NewRow, 11).Value = Worksheets("input").Range("B13").Value
Worksheets("Data").Cells(NewRow, 12).Value = Worksheets("input").Range("B14").Value
Worksheets("Data").Cells(NewRow, 13).Value = Worksheets("input").Range("B15").Value
Worksheets("Data").Cells(NewRow, 14).Value = Worksheets("input").Range("B16").Value
Worksheets("Data").Cells(NewRow, 15).Value = Worksheets("input").Range("B17").Value
Worksheets("Data").Cells(NewRow, 16).Value = Worksheets("input").Range("B18").Value
Worksheets("Data").Cells(NewRow, 17).Value = Worksheets("input").Range("B19").Value
Worksheets("Data").Cells(NewRow, 18).Value = Worksheets("input").Range("B20").Value
Worksheets("Data").Cells(NewRow, 19).Value = Worksheets("input").Range("B21").Value
Worksheets("Data").Cells(NewRow, 20).Value = Worksheets("input").Range("B22").Value
Worksheets("Data").Cells(NewRow, 21).Value = Worksheets("input").Range("B23").Value
Worksheets("Data").Cells(NewRow, 22).Value = Worksheets("input").Range("B24").Value
Worksheets("Data").Cells(NewRow, 23).Value = Worksheets("input").Range("B25").Value
Worksheets("Data").Cells(NewRow, 24).Value = Worksheets("input").Range("B26").Value
Worksheets("Data").Cells(NewRow, 25).Value = Worksheets("input").Range("B27").Value
Worksheets("Data").Cells(NewRow, 26).Value = Worksheets("input").Range("B28").Value
Worksheets("Data").Cells(NewRow, 27).Value = Worksheets("input").Range("B29").Value
Worksheets("Data").Cells(NewRow, 28).Value = Worksheets("input").Range("B30").Value
Worksheets("Data").Cells(NewRow, 29).Value = Worksheets("input").Range("B31").Value
Worksheets("Data").Cells(NewRow, 30).Value = Worksheets("input").Range("B32").Value
Worksheets("Data").Cells(NewRow, 31).Value = Worksheets("input").Range("B33").Value
Worksheets("Data").Cells(NewRow, 32).Value = Worksheets("input").Range("B34").Value
Worksheets("Data").Cells(NewRow, 33).Value = Worksheets("input").Range("B35").Value
Worksheets("Data").Cells(NewRow, 34).Value = Worksheets("input").Range("B36").Value
Worksheets("Data").Cells(NewRow, 35).Value = Worksheets("input").Range("B37").Value
'Range("B38") is a heading
Worksheets("Data").Cells(NewRow, 36).Value = Worksheets("input").Range("B39").Value
Worksheets("Data").Cells(NewRow, 37).Value = Worksheets("input").Range("B40").Value
Worksheets("Data").Cells(NewRow, 38).Value = Worksheets("input").Range("B41").Value
Worksheets("Data").Cells(NewRow, 39).Value = Worksheets("input").Range("B42").Value
Worksheets("Data").Cells(NewRow, 40).Value = Worksheets("input").Range("B43").Value
Worksheets("Data").Cells(NewRow, 41).Value = Worksheets("input").Range("B44").Value
Worksheets("Data").Cells(NewRow, 42).Value = Worksheets("input").Range("B45").Value
Worksheets("Data").Cells(NewRow, 43).Value = Worksheets("input").Range("B46").Value
Worksheets("Data").Cells(NewRow, 44).Value = Worksheets("input").Range("B47").Value
Worksheets("Data").Cells(NewRow, 45).Value = Worksheets("input").Range("B48").Value
Worksheets("Data").Cells(NewRow, 46).Value = Worksheets("input").Range("B49").Value
Worksheets("Data").Cells(NewRow, 47).Value = Worksheets("input").Range("B50").Value
Worksheets("Data").Cells(NewRow, 48).Value = Worksheets("input").Range("B51").Value
Worksheets("Data").Cells(NewRow, 49).Value = Worksheets("input").Range("B52").Value
Worksheets("Data").Cells(NewRow, 50).Value = Worksheets("input").Range("B53").Value
Worksheets("Data").Cells(NewRow, 51).Value = Worksheets("input").Range("B54").Value
Worksheets("Data").Cells(NewRow, 52).Value = Worksheets("input").Range("B55").Value
Sheets("Input").Select
Range("C2").Value = "Data added"
MsgBox "Data added", vbOKOnly, "Transfer Data"
Worksheets("input").Range("E1").Value = NewRow
Worksheets("input").Range("B3").Select
End Sub
Consider replacing the 52 lines transposing the data with one line inside a For/Next loop
Option Explicit
Sub add_to_table_sa_3()
Dim NewRow As Long, i as Long, arData
With Sheets("Input")
If .Range("F1").Value <> 0 Then
MsgBox "There are errors. No data has been added!", vbOKOnly, "Warning!"
Exit Sub
End If
arData = .Range("B3:B55").Value
NewRow = .Range("E1").Value + 1
End With
With Sheets("Data")
For i = 1 To 35
.Cells(NewRow, i) = arData(i, 1)
Next
'Range("B38") is a heading
For i = 37 To 65
.Cells(NewRow, i - 1) = arData(i, 1)
Next
'Range("B68") is a heading
For i = 67 To UBound(arData)
.Cells(NewRow, i - 2) = arData(i, 1)
Next
Sheet1.ComboBox1.ListFillRange = "'" & .Name & "'!A2:A" & NewRow
Sheet6.ComboBox2.ListFillRange = "'" & .Name & "'!A2:A" & NewRow
End With
With Sheets("Input")
.Range("C2").Value = "Data added"
.Range("E1").Value = NewRow
.Activate
.Range("B3").Select
End With
MsgBox "Data added row " & NewRow, vbOKOnly, "Transfer Data"
End Sub

Invalid Property Value error for Userform

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.

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

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

Compile error End with without with

i keep getting a compile message 'end with without with'
im new to this and i cant see a problem i have a 'With' followed by and 'End with'. if i remove the end with i get a if with out end if.
Private Sub Submitnewcustomer_Click()
Dim RowCount As Long
Dim ctl As Control
If Me.companynameinput.Value = "" Then
MsgBox "Please enter a Company Name.", vbExclamation, "Britannia Monitoring Systems"
Me.companynameinput.SetFocus
Exit Sub
End If
If Me.contactnameinput.Value = "" Then
MsgBox "Please enter a Contact Name.", vbExclamation, "Britannia Monitoring Systems"
Me.companynameinput.SetFocus
Exit Sub
End If
If Me.addressinput.Value = "" Then
MsgBox "Please enter an Address.", vbExclamation, "Britannia Monitoring Systems"
Me.companynameinput.SetFocus
Exit Sub
End If
If Me.Telphone1input.Value = "" Then
MsgBox "Please enter at least 1 phone Number.", vbExclamation, "Britannia Monitoring Systems"
Me.Telphone1input.SetFocus
Exit Sub
End If
If Me.email1input.Value = "" Then
MsgBox "Please enter at least 1 Email Address.", vbExclamation, "Britannia Monitoring Systems"
Me.email1input.SetFocus
End If
RowCount = Worksheets("Database").Range("A1").CurrentRegion.Rows.Count
With Worksheets("Database").Range("A1")
.Offset(RowCount, 0).Value = Me.companynameinput.Value
.Offset(RowCount, 1).Value = Me.contactnameinput.Value
.Offset(RowCount, 2).Value = Me.Telphone1input.Value
.Offset(RowCount, 3).Value = Me.telephone2input.Value
.Offset(RowCount, 4).Value = Me.email1input.Value
.Offset(RowCount, 5).Value = Me.email2input.Value
.Offset(RowCount, 6).Value = Me.email3input.Value
.Offset(RowCount, 7).Value = Me.email4input.Value
.Offset(RowCount, 8).Value = Me.addressinput.Value
.Offset(RowCount, 15).Value = Format(Now, "dd/mm/yyyy hh:nn:ss")
If Me.CheckBox1.Value = True Then
.Offset(RowCount, 12).Value = "Yes"
Else
.Offset(RowCount, 12).Value = "No"
If Me.CheckBox2.Value = True Then
.Offset(RowCount, 13).Value = "Yes"
Else
.Offset(RowCount, 13).Value = "No"
If Me.CheckBox3.Value = True Then
.Offset(RowCount, 14).Value = "Yes"
Else
.Offset(RowCount, 14).Value = "No"
End If
End With
For Each ctl In Me.Controls
If TypeName(ctl) = "TextBox" Or TypeName(ctl) = "ComboBox" Then
ctl.Value = ""
ElseIf TypeName(ctl) = "CheckBox" Then
ctl.Value = False
End If
Next ctl
End Sub
I have just struggled for 30 minutes just to post this on here
any help would be great thanks
You are missing a couple of End Ifs in this section. You'll need to sort that out before your code will compile correctly.
If Me.CheckBox1.Value = True Then
.Offset(RowCount, 12).Value = "Yes"
Else
.Offset(RowCount, 12).Value = "No"
If Me.CheckBox2.Value = True Then
.Offset(RowCount, 13).Value = "Yes"
Else
.Offset(RowCount, 13).Value = "No"
If Me.CheckBox3.Value = True Then
.Offset(RowCount, 14).Value = "Yes"
Else
.Offset(RowCount, 14).Value = "No"
End If

Resources