I use this userform to add data to a spreadsheet.
but how do i unload it and reload using the same criteria in the UserForm_Initialize. Can i get it to update after every entry ? or can i assign it to a button or both ? I have a botton to call the userform that is just userform1.show .
Code for userform -
'Written by Julian Smith April 2008
Private Sub ComboBox1_Change()
End Sub
Private Sub ComboBox2_Change()
End Sub
Private Sub ComboBox3_Change()
End Sub
Private Sub CommandButton1_Click()
Application.ScreenUpdating = True
' Find next empty row
Worksheets("RESULTS").Select
Range("A1").Select
Do Until ActiveCell.Value = ""
ActiveCell.Offset(1, 0).Select
Loop
' Write values to next empty row
ActiveCell.Value = ComboBox1
ActiveCell.Offset(0, 1).Value = TextBox2
ActiveCell.Offset(0, 2).Value = TextBox3
ActiveCell.Offset(0, 3).Value = TextBox4
ActiveCell.Offset(0, 4).Value = TextBox6 'TextBox5
ActiveCell.Offset(0, 5).Value = TextBox6
ActiveCell.Offset(0, 6).Value = ComboBox3
ActiveCell.Offset(0, 7).Value = ComboBox2
ActiveCell.Offset(0, 8).Value = TextBox9
ActiveCell.Offset(0, 9).Value = TextBox5 'TextBox10
ActiveCell.Offset(0, 10).Value = TextBox10
ActiveCell.Offset(0, 11).Value = TextBox11
ActiveCell.Offset(0, 12).Value = TextBox12
' Clear all textboxes
ComboBox1.Value = ""
TextBox2.Value = ""
TextBox3.Value = ""
TextBox4.Value = ""
TextBox5.Value = ""
TextBox6.Value = ""
ComboBox3.Value = ""
ComboBox2.Value = ""
TextBox9.Value = ""
TextBox10.Value = ""
TextBox11.Value = ""
TextBox12.Value = ""
ComboBox1.SetFocus
Dim nextnumber As Long
Dim rNumbers As Range
Unload UserForm1
End Sub
Private Sub CommandButton2_Click()
' Remove textbox
Unload UserForm1
End Sub
Private Sub CommandButton3_Click()
UserForm2.Show
End Sub
Private Sub CommandButton4_Click()
ThisWorkbook.Save
Application.Quit
End Sub
Sub send()
'
' send Macro
' Macro recorded 30/08/2007 by JSmith3
'
'
Sheets("Report").Select
Range("A1:J60").Select
Selection.Copy
Workbooks.Add
ActiveSheet.Paste
Application.CutCopyMode = False
Application.Dialogs(xlDialogSendMail).Show
End Sub
Private Sub CommandButton5_Click()
Sheets("Report").Select
Range("A1:J60").Select
Selection.Copy
Workbooks.Add
ActiveSheet.Paste
Application.CutCopyMode = False
Application.Dialogs(xlDialogSendMail).Show
End Sub
Private Sub Label1_Click()
End Sub
Private Sub Label10_Click()
End Sub
Private Sub Label15_Click()
End Sub
Private Sub Label16_Click()
End Sub
Private Sub Label20_Click()
End Sub
Private Sub Label21_Click()
End Sub
Private Sub Label22_Click()
End Sub
Private Sub Label3_Click()
End Sub
Private Sub ListBox1_Click()
End Sub
Private Sub Label7_Click()
End Sub
Private Sub TextBox10_Change()
TextBox11.Value = ((Val(TextBox5.Value) + Val(TextBox10.Value)) / 2)
End Sub
Private Sub TextBox11_Change()
End Sub
Private Sub TextBox12_Change()
End Sub
Private Sub TextBox3_Change()
End Sub
Private Sub TextBox5_Change()
End Sub
Private Sub UserForm_Initialize()
Dim nextnumber As Long
Dim rNumbers As Range
Set rNumbers = Sheets("RESULTS").Range(Cells(3, 3), Cells(Rows.Count, 3).End(xlUp))
Application.ScreenUpdating = False
With Worksheets("DATA")
UserForm1.ComboBox1.List = .Range(.Cells(2, 1), .Cells(.Rows.Count, 1).End(xlUp)).Value
UserForm1.ComboBox2.List = .Range(.Cells(2, 2), .Cells(.Rows.Count, 2).End(xlUp)).Value
UserForm1.ComboBox3.List = .Range(.Cells(2, 3), .Cells(.Rows.Count, 3).End(xlUp)).Value
End With
nextnumber = Application.WorksheetFunction.Max(rNumbers) + 1
UserForm1.TextBox3.Value = nextnumber 'ActiveCell.Value + 1
End Sub
Bookmarks