AndrewGKenneth
Board Regular
- Joined
- Aug 6, 2018
- Messages
- 59
Hi there,
I have created a userform but when adding data to my spreadsheet it is very slow and takes around 30 seconds to input data from the userform to the spreadsheet. Here is my code for my add button, is there anything wrong with my code that is causing it to be slow? Any help would be much appreciated.
Thanks,
Andrew
I have created a userform but when adding data to my spreadsheet it is very slow and takes around 30 seconds to input data from the userform to the spreadsheet. Here is my code for my add button, is there anything wrong with my code that is causing it to be slow? Any help would be much appreciated.
Code:
Private Sub CommandButton_Add_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Sheet1")
'Check for Customer Number
If Trim(Me.TextBox_LotNumber.Value) = "" Or Me.TextBox_JobNumber.Value = "" Or Me.TextBox_FG.Value = "" Then
Me.TextBox_LotNumber.SetFocus
MsgBox "Please complete all fields"
Exit Sub
End If
'Find first empty row in database
EmptyRow = WorksheetFunction.CountA(Range("B:B")) + 1
Cells(EmptyRow, 1).Value = TextBox_JobNumber.Value
Cells(EmptyRow, 2).Value = TextBox_Start.Value
Cells(EmptyRow, 4).Value = TextBox_End.Value
Cells(EmptyRow, 6).Value = TextBox_LotNumber.Value
Cells(EmptyRow, 7).Value = TextBox_ProductNumber.Value
Cells(EmptyRow, 8).Value = TextBox_PartName.Value
Cells(EmptyRow, 9).Value = TextBox_DrawingNumber.Value
Cells(EmptyRow, 10).Value = TextBox_Customer.Value
Cells(EmptyRow, 11).Value = TextBox_Order.Value
Cells(EmptyRow, 12).Value = TextBox_FG.Value
Cells(EmptyRow, 13).Value = TextBox_NG.Value
Cells(EmptyRow, 14).Value = TextBox_MAT_NG.Value
TextBox_Start.Value = ""
TextBox_End.Value = ""
TextBox_LotNumber.Value = ""
TextBox_ProductNumber.Value = ""
TextBox_PartName.Value = ""
TextBox_DrawingNumber.Value = ""
TextBox_Customer.Value = ""
TextBox_Order.Value = ""
TextBox_FG.Value = ""
TextBox_NG.Value = ""
TextBox_MAT_NG.Value = ""
MsgBox "Data Added", vbOKOnly + vbInformation, "Data Added"
'clear the data
TextBox_JobNumber.Value = ""
TextBox_Start.Value = ""
TextBox_End.Value = ""
TextBox_LotNumber.Value = ""
TextBox_ProductNumber.Value = ""
TextBox_PartName.Value = ""
TextBox_DrawingNumber.Value = ""
TextBox_Customer.Value = ""
TextBox_Order.Value = ""
TextBox_FG.Value = ""
TextBox_NG.Value = ""
TextBox_MAT_NG.Value = ""
End Sub
Andrew
Last edited by a moderator: