unable to save the userform dat to worksheet
VBA Code:
Private Sub CmdBtnSUBMIT_Click()
If VBA.IsNumeric(Me.TxtDISTCODE.Value) = False Then
MsgBox "Please enter DIST CODE", vbCritical
Else: Exit Sub
End If
If ComboBoxDEALER.Value = "" Then
MsgBox "Please select Dealer", vbCritical
Exit Sub
End If
If ComboBoxDIVISION.Value = "" Then
MsgBox "Please select Division", vbCritical
Exit Sub
End If
If ComboBoxCATEGORY.Value = "" Then
MsgBox "Please select Category", vbCritical
Exit Sub
End If
If ComboBoxSUBCATEGORY.Value = "" Then
MsgBox "Please select Sub-Category", vbCritical
Exit Sub
End If
If ComboBoxMODEL.Value = "" Then
MsgBox "Please select Model", vbCritical
Exit Sub
End If
If ComboBoxPRODUCTCODE.Value = "" Then
MsgBox "Please select Product-Code", vbCritical
Exit Sub
End If
If ComboBoxCOLOUR.Value = "" Then
MsgBox "Please select Colour", vbCritical
Exit Sub
End If
If VBA.IsNumeric(Me.TxtBILLEDQTY.Value) = False Then
MsgBox "Please enter BILLED QTY", vbCritical
Else: Exit Sub
End If
If VBA.IsNumeric(Me.TxtFREEQTY.Value) = FASLE Then
MsgBox "Please enter FREE QTY", vbCritical
Else: Exit Sub
End If
Dim erow As Long
Dim SD As Worksheet
Set SD = ThisWorkbook.Sheets("Sales Data")
erow = SD.Range("A" & Rows.Count).End(xlUp).Row
SD.Cells(erow + 1, "A").Value = TxtDATE.Text
SD.Cells(erow + 1, "B").Value = TxtDISTCODE.Text
SD.Cells(erow + 1, "C").Value = ComboBoxDEALER.Text
SD.Cells(erow + 1, "D").Value = ComboBoxDIVISION.Text
SD.Cells(erow + 1, "E").Value = ComboBoxCATEGORY.Text
SD.Cells(erow + 1, "F").Value = ComboBoxSUBCATEGORY.Text
SD.Cells(erow + 1, "G").Value = ComboBoxMODEL.Text
SD.Cells(erow + 1, "H").Value = ComboBoxPRODUCTCODE.Text
SD.Cells(erow + 1, "I").Value = ComboBoxCOLOUR.Text
SD.Cells(erow + 1, "J").Value = TxtBILLEDQTY.Text
SD.Cells(erow + 1, "K").Value = TxtFREEQTY.Text
End Sub
Private Sub ComboBoxCATEGORY_Change()
Dim SH As Worksheet
Set SH = ThisWorkbook.Sheets("TABLES")
Dim I As Integer
Me.ComboBoxSUBCATEGORY.Clear
For I = 2 To SH.Range("T" & Application.Rows.Count).End(xlUp).Row
If SH.Range("T" & I).Value = "SUB-CATEGORY" Then
If SH.Range("V" & I).Value = Me.ComboBoxCATEGORY.Value Then
Me.ComboBoxSUBCATEGORY.AddItem SH.Range("U" & I)
End If
End If
Next I
End Sub
Private Sub ComboBoxDIVISION_Change()
Dim SH As Worksheet
Set SH = ThisWorkbook.Sheets("TABLES")
Dim I As Integer
Me.ComboBoxCATEGORY.Clear
For I = 2 To SH.Range("T" & Application.Rows.Count).End(xlUp).Row
If SH.Range("T" & I).Value = "CATEGORY" Then
If SH.Range("V" & I).Value = Me.ComboBoxDIVISION.Value Then
Me.ComboBoxCATEGORY.AddItem SH.Range("U" & I)
End If
End If
Next I
End Sub
Private Sub ComboBoxMODEL_Change()
Dim SH As Worksheet
Set SH = ThisWorkbook.Sheets("TABLES")
Dim I As Integer
Me.ComboBoxPRODUCTCODE.Clear
For I = 2 To SH.Range("T" & Application.Rows.Count).End(xlUp).Row
If SH.Range("T" & I).Value = "PRODUCT-CODE" Then
If SH.Range("V" & I).Value = Me.ComboBoxMODEL.Value Then
Me.ComboBoxPRODUCTCODE.AddItem SH.Range("U" & I)
End If
End If
Next I
End Sub
Private Sub ComboBoxPRODUCTCODE_Change()
Dim SH As Worksheet
Set SH = ThisWorkbook.Sheets("TABLES")
Dim I As Integer
Me.ComboBoxCOLOUR.Clear
For I = 2 To SH.Range("T" & Application.Rows.Count).End(xlUp).Row
If SH.Range("T" & I).Value = "COLOUR" Then
If SH.Range("V" & I).Value = Me.ComboBoxPRODUCTCODE.Value Then
Me.ComboBoxCOLOUR.AddItem SH.Range("U" & I)
End If
End If
Next I
End Sub
Private Sub ComboBoxSUBCATEGORY_Change()
Dim SH As Worksheet
Set SH = ThisWorkbook.Sheets("TABLES")
Dim I As Integer
Me.ComboBoxMODEL.Clear
For I = 2 To SH.Range("T" & Application.Rows.Count).End(xlUp).Row
If SH.Range("T" & I).Value = "MODEL" Then
If SH.Range("V" & I).Value = Me.ComboBoxSUBCATEGORY.Value Then
Me.ComboBoxMODEL.AddItem SH.Range("U" & I)
End If
End If
Next I
End Sub
Private Sub TxtDISTCODE_Change()
Dim DD As Worksheet
Set DD = ThisWorkbook.Sheets("DEALER DATA")
Dim I As Integer
Me.ComboBoxDEALER.Clear
For I = 2 To DD.Range("A" & Application.Rows.Count).End(xlUp).Row
If DD.Range("A" & I).Value = TxtDISTCODE.Text Then
Me.ComboBoxDEALER.AddItem DD.Range("B" & I)
End If
Next I
End Sub
Private Sub UserFORM_ACTIVATE()
Dim SH As Worksheet
Set SH = ThisWorkbook.Sheets("TABLES")
Dim I As Integer
Me.ComboBoxDIVISION.Clear
For I = 2 To SH.Range("T" & Application.Rows.Count).End(xlUp).Row
If SH.Range("T" & I).Value = "DIVISION" Then
Me.ComboBoxDIVISION.AddItem SH.Range("U" & I)
End If
Next I
End Sub