I am VERY new to VBA and have learned how to build a userform and have built a basic one using guidelines I have found online. The userform captures basic data through text boxes, radio buttons and check boxes and exports it to the next free line on a worksheet in the workbook. It works perfectly.
Now what I want to do is be able to edit a record that was entered through the userform without going to the data on the output worksheet, but rather using a userform. Do I need to build a new userform for editing? Is there code I can add to my existing userform to accomplish this? I want to be able to pull up all the data based on the ID text field, make any changes and export it to the same row it came from.
Any help would be greatly appreciated - and remember, I am a new user!
My code:
Private Sub AddButton_Click()
Dim emptyRow As Long
'Make Sheet 1 (Data) Active
Sheets(2).Activate
'Determine Empty Row
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
'Export Data to Worksheet
Cells(emptyRow, 1).Value = IDtxt.Value
Cells(emptyRow, 2).Value = Nametxt.Value
Cells(emptyRow, 3).Value = Desctxt.Value
If OnBoardingBox.Value = True Then Cells(emptyRow, 4).Value = "On-Boarding"
If SalesDeepeningBox.Value = True Then Cells(emptyRow, 5).Value = "Sales Deepening"
If ServiceBox.Value = True Then Cells(emptyRow, 6).Value = "Service"
If RetentionBox.Value = True Then Cells(emptyRow, 7).Value = "Retention"
If RiskBox.Value = True Then Cells(emptyRow, 8).Value = "Risk"
If DirectMailBox.Value = True Then Cells(emptyRow, 9).Value = "Direct Mail"
If EmailBox.Value = True Then Cells(emptyRow, 10).Value = "Email"
If ChatBox.Value = True Then Cells(emptyRow, 11).Value = "Chat"
If MobileBox.Value = True Then Cells(emptyRow, 12).Value = "Mobile"
Cells(emptyRow, 13).Value = Fromtxt.Value
Cells(emptyRow, 14).Value = Totxt.Value
If NearRealButton.Value = True Then
Cells(emptyRow, 15).Value = "Near Real-Time"
Else
If DailyButton.Value = True Then
Cells(emptyRow, 15).Value = "Daily"
Else
If WeeklyButton.Value = True Then
Cells(emptyRow, 15).Value = "Weekly"
Else
If MonthButton.Value = True Then
Cells(emptyRow, 15).Value = "Month End"
Else
If QuarterButton.Value = True Then
Cells(emptyRow, 15).Value = "Quarter End"
Else
If YearButton.Value = True Then
Cells(emptyRow, 15).Value = "Year End"
End If
End If
End If
End If
End If
End If
Cells(emptyRow, 16).Value = NotesBox.Value
'check for a Trigger ID
If Trim(Me.IDtxt.Value) = "" Then
Me.IDtxt.SetFocus
MsgBox "Please enter an ID"
Exit Sub
End If
'clear the data
Me.IDtxt.Value = ""
Me.Nametxt.Value = ""
Me.Desctxt.Value = ""
Me.OnBoardingBox.Value = False
Me.SalesDeepeningBox.Value = False
Me.ServiceBox.Value = False
Me.RetentionBox.Value = False
Me.RiskBox.Value = False
Me.DirectMailBox.Value = False
Me.EmailBox.Value = False
Me.ChatBox.Value = False
Me.MobileBox.Value = False
Me.Fromtxt.Value = ""
Me.Totxt.Value = ""
Me.NearRealButton.Value = False
Me.DailyButton.Value = False
Me.WeeklyButton.Value = False
Me.MonthButton.Value = False
Me.QuarterButton.Value = False
Me.YearButton.Value = False
Me.NotesBox.Value = ""
Me.IDtxt.SetFocus
MsgBox "You have successfully submitted the data"
End Sub
Private Sub CancelButton_Click()
Unload Me
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "Please click the Cancel /Clear Button to Close the Form WITHOUT submitting the data"
End If
End Sub
Now what I want to do is be able to edit a record that was entered through the userform without going to the data on the output worksheet, but rather using a userform. Do I need to build a new userform for editing? Is there code I can add to my existing userform to accomplish this? I want to be able to pull up all the data based on the ID text field, make any changes and export it to the same row it came from.
Any help would be greatly appreciated - and remember, I am a new user!
My code:
Private Sub AddButton_Click()
Dim emptyRow As Long
'Make Sheet 1 (Data) Active
Sheets(2).Activate
'Determine Empty Row
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 1
'Export Data to Worksheet
Cells(emptyRow, 1).Value = IDtxt.Value
Cells(emptyRow, 2).Value = Nametxt.Value
Cells(emptyRow, 3).Value = Desctxt.Value
If OnBoardingBox.Value = True Then Cells(emptyRow, 4).Value = "On-Boarding"
If SalesDeepeningBox.Value = True Then Cells(emptyRow, 5).Value = "Sales Deepening"
If ServiceBox.Value = True Then Cells(emptyRow, 6).Value = "Service"
If RetentionBox.Value = True Then Cells(emptyRow, 7).Value = "Retention"
If RiskBox.Value = True Then Cells(emptyRow, 8).Value = "Risk"
If DirectMailBox.Value = True Then Cells(emptyRow, 9).Value = "Direct Mail"
If EmailBox.Value = True Then Cells(emptyRow, 10).Value = "Email"
If ChatBox.Value = True Then Cells(emptyRow, 11).Value = "Chat"
If MobileBox.Value = True Then Cells(emptyRow, 12).Value = "Mobile"
Cells(emptyRow, 13).Value = Fromtxt.Value
Cells(emptyRow, 14).Value = Totxt.Value
If NearRealButton.Value = True Then
Cells(emptyRow, 15).Value = "Near Real-Time"
Else
If DailyButton.Value = True Then
Cells(emptyRow, 15).Value = "Daily"
Else
If WeeklyButton.Value = True Then
Cells(emptyRow, 15).Value = "Weekly"
Else
If MonthButton.Value = True Then
Cells(emptyRow, 15).Value = "Month End"
Else
If QuarterButton.Value = True Then
Cells(emptyRow, 15).Value = "Quarter End"
Else
If YearButton.Value = True Then
Cells(emptyRow, 15).Value = "Year End"
End If
End If
End If
End If
End If
End If
Cells(emptyRow, 16).Value = NotesBox.Value
'check for a Trigger ID
If Trim(Me.IDtxt.Value) = "" Then
Me.IDtxt.SetFocus
MsgBox "Please enter an ID"
Exit Sub
End If
'clear the data
Me.IDtxt.Value = ""
Me.Nametxt.Value = ""
Me.Desctxt.Value = ""
Me.OnBoardingBox.Value = False
Me.SalesDeepeningBox.Value = False
Me.ServiceBox.Value = False
Me.RetentionBox.Value = False
Me.RiskBox.Value = False
Me.DirectMailBox.Value = False
Me.EmailBox.Value = False
Me.ChatBox.Value = False
Me.MobileBox.Value = False
Me.Fromtxt.Value = ""
Me.Totxt.Value = ""
Me.NearRealButton.Value = False
Me.DailyButton.Value = False
Me.WeeklyButton.Value = False
Me.MonthButton.Value = False
Me.QuarterButton.Value = False
Me.YearButton.Value = False
Me.NotesBox.Value = ""
Me.IDtxt.SetFocus
MsgBox "You have successfully submitted the data"
End Sub
Private Sub CancelButton_Click()
Unload Me
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "Please click the Cancel /Clear Button to Close the Form WITHOUT submitting the data"
End If
End Sub