Hi there.
I have a userform with a multipage layout. the code I am using to pull the data from a single page is below. Is there a way I can use this on each page without having to have to rename all of the elements on each page and re run the code every time? Hope that makes sense?
Private Sub CommandButton1_Click()
Dim LastRow As Long, ws As Worksheet
Set ws = Sheets("Data")
LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row + 1
ws.Range("A" & LastRow).Value = ComboBox1.Text
ws.Range("B" & LastRow).Value = ComboBox2.Text
ws.Range("C" & LastRow).Value = Label1
ws.Range("D" & LastRow).Value = Label2
If OptionButton1 = True Then ws.Range("E" & LastRow).Value = "Pass" Else ws.Range("E" & LastRow).Value = ""
If OptionButton2 = True Then ws.Range("F" & LastRow).Value = "Fail" Else ws.Range("F" & LastRow).Value = ""
If OptionButton3 = True Then ws.Range("G" & LastRow).Value = "Exemption" Else ws.Range("G" & LastRow).Value = ""
ws.Range("H" & LastRow).Value = TextBox1.Text
ws.Range("I" & LastRow).Value = TextBox2.Text
ws.Range("J" & LastRow).Value = TextBox3.Text
ComboBox1.Value = ""
ComboBox2.Value = ""
Label1.Caption = ""
Label2.Caption = ""
OptionButton1.Value = False
OptionButton2.Value = False
OptionButton3.Value = False
TextBox1.Value = ""
TextBox2.Value = ""
TextBox3.Value = ""
I have a userform with a multipage layout. the code I am using to pull the data from a single page is below. Is there a way I can use this on each page without having to have to rename all of the elements on each page and re run the code every time? Hope that makes sense?
Private Sub CommandButton1_Click()
Dim LastRow As Long, ws As Worksheet
Set ws = Sheets("Data")
LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row + 1
ws.Range("A" & LastRow).Value = ComboBox1.Text
ws.Range("B" & LastRow).Value = ComboBox2.Text
ws.Range("C" & LastRow).Value = Label1
ws.Range("D" & LastRow).Value = Label2
If OptionButton1 = True Then ws.Range("E" & LastRow).Value = "Pass" Else ws.Range("E" & LastRow).Value = ""
If OptionButton2 = True Then ws.Range("F" & LastRow).Value = "Fail" Else ws.Range("F" & LastRow).Value = ""
If OptionButton3 = True Then ws.Range("G" & LastRow).Value = "Exemption" Else ws.Range("G" & LastRow).Value = ""
ws.Range("H" & LastRow).Value = TextBox1.Text
ws.Range("I" & LastRow).Value = TextBox2.Text
ws.Range("J" & LastRow).Value = TextBox3.Text
ComboBox1.Value = ""
ComboBox2.Value = ""
Label1.Caption = ""
Label2.Caption = ""
OptionButton1.Value = False
OptionButton2.Value = False
OptionButton3.Value = False
TextBox1.Value = ""
TextBox2.Value = ""
TextBox3.Value = ""