I have 2 Combo boxes and 1 Textbox that must have data in them at top of userform
Then there are a further 6 rows of 6 textboxes , if some of the 6 rows of textboxes are left blank, when Data is sent to the sheet via the Enter Button (CommandButton2) I need to prevent the empty textboxes being loaded onto the sheet
Below is the code I have to send data to sheet
Private Sub CommandButton2_Click()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Sheet3")
Dim Last_Row As Long
Last_Row = Application.WorksheetFunction.CountA(sh.Range("A:A"))
sh.Range("A" & Last_Row + 1).Value = "=Row()-1"
sh.Range("B" & Last_Row + 1).Value = Now
sh.Range("C" & Last_Row + 1).Value = UserForm5.ComboBox2.Value
sh.Range("D" & Last_Row + 1).Value = UserForm5.TextBox2.Value
sh.Range("E" & Last_Row + 1).Value = UserForm5.ComboBox1.Value
sh.Range("F" & Last_Row + 1).Value = UserForm5.TextBox3.Value
sh.Range("H" & Last_Row + 1).Value = UserForm5.TextBox5.Value
sh.Range("J" & Last_Row + 1).Value = UserForm5.TextBox7.Value
sh.Range("K" & Last_Row + 1).Value = UserForm5.TextBox8.Value
sh.Range("I" & Last_Row + 1).Value = UserForm5.TextBox6.Value
sh.Range("L" & Last_Row + 1).Value = UserForm5.TextBox10.Value
sh.Range("A" & Last_Row + 2).Value = "=Row()-1"
sh.Range("B" & Last_Row + 2).Value = Now
sh.Range("C" & Last_Row + 2).Value = UserForm5.ComboBox2.Value
sh.Range("D" & Last_Row + 2).Value = UserForm5.TextBox2.Value
sh.Range("E" & Last_Row + 2).Value = UserForm5.ComboBox1.Value
sh.Range("F" & Last_Row + 2).Value = UserForm5.TextBox11.Value
sh.Range("H" & Last_Row + 2).Value = UserForm5.TextBox15.Value
sh.Range("J" & Last_Row + 2).Value = UserForm5.TextBox19.Value
sh.Range("K" & Last_Row + 2).Value = UserForm5.TextBox23.Value
sh.Range("I" & Last_Row + 2).Value = UserForm5.TextBox27.Value
sh.Range("L" & Last_Row + 2).Value = UserForm5.TextBox31.Value
sh.Range("A" & Last_Row + 3).Value = "=Row()-1"
sh.Range("B" & Last_Row + 3).Value = Now
sh.Range("C" & Last_Row + 3).Value = UserForm5.ComboBox2.Value
sh.Range("D" & Last_Row + 3).Value = UserForm5.TextBox2.Value
sh.Range("E" & Last_Row + 3).Value = UserForm5.ComboBox1.Value
sh.Range("F" & Last_Row + 3).Value = UserForm5.TextBox12.Value
sh.Range("H" & Last_Row + 3).Value = UserForm5.TextBox16.Value
sh.Range("J" & Last_Row + 3).Value = UserForm5.TextBox20.Value
sh.Range("K" & Last_Row + 3).Value = UserForm5.TextBox24.Value
sh.Range("I" & Last_Row + 3).Value = UserForm5.TextBox28.Value
sh.Range("L" & Last_Row + 3).Value = UserForm5.TextBox32.Value
sh.Range("A" & Last_Row + 4).Value = "=Row()-1"
sh.Range("B" & Last_Row + 4).Value = Now
sh.Range("C" & Last_Row + 4).Value = UserForm5.ComboBox2.Value
sh.Range("D" & Last_Row + 4).Value = UserForm5.TextBox2.Value
sh.Range("E" & Last_Row + 4).Value = UserForm5.ComboBox1.Value
sh.Range("F" & Last_Row + 4).Value = UserForm5.TextBox13.Value
sh.Range("H" & Last_Row + 4).Value = UserForm5.TextBox17.Value
sh.Range("J" & Last_Row + 4).Value = UserForm5.TextBox21.Value
sh.Range("K" & Last_Row + 4).Value = UserForm5.TextBox25.Value
sh.Range("I" & Last_Row + 4).Value = UserForm5.TextBox29.Value
sh.Range("L" & Last_Row + 4).Value = UserForm5.TextBox33.Value
sh.Range("A" & Last_Row + 5).Value = "=Row()-1"
sh.Range("B" & Last_Row + 5).Value = Now
sh.Range("C" & Last_Row + 5).Value = UserForm5.ComboBox2.Value
sh.Range("D" & Last_Row + 5).Value = UserForm5.TextBox2.Value
sh.Range("E" & Last_Row + 5).Value = UserForm5.ComboBox1.Value
sh.Range("F" & Last_Row + 5).Value = UserForm5.TextBox14.Value
sh.Range("H" & Last_Row + 5).Value = UserForm5.TextBox18.Value
sh.Range("J" & Last_Row + 5).Value = UserForm5.TextBox22.Value
sh.Range("K" & Last_Row + 5).Value = UserForm5.TextBox26.Value
sh.Range("I" & Last_Row + 5).Value = UserForm5.TextBox30.Value
sh.Range("L" & Last_Row + 5).Value = UserForm5.TextBox34.Value
sh.Range("A" & Last_Row + 6).Value = "=Row()-1"
sh.Range("B" & Last_Row + 6).Value = Now
sh.Range("C" & Last_Row + 6).Value = UserForm5.ComboBox2.Value
sh.Range("D" & Last_Row + 6).Value = UserForm5.TextBox2.Value
sh.Range("E" & Last_Row + 6).Value = UserForm5.ComboBox1.Value
sh.Range("F" & Last_Row + 6).Value = UserForm5.TextBox35.Value
sh.Range("H" & Last_Row + 6).Value = UserForm5.TextBox36.Value
sh.Range("J" & Last_Row + 6).Value = UserForm5.TextBox37.Value
sh.Range("K" & Last_Row + 6).Value = UserForm5.TextBox38.Value
sh.Range("I" & Last_Row + 6).Value = UserForm5.TextBox39.Value
sh.Range("L" & Last_Row + 6).Value = UserForm5.TextBox40.Value
UserForm5.ComboBox1.Value = ""
UserForm5.ComboBox2.Value = ""
UserForm5.TextBox2.Value = ""
UserForm5.TextBox3.Value = ""
UserForm5.TextBox5.Value = ""
UserForm5.TextBox6.Value = ""
UserForm5.TextBox7.Value = ""
UserForm5.TextBox8.Value = ""
UserForm5.TextBox10.Value = ""
UserForm5.ComboBox1.Value = ""
UserForm5.ComboBox2.Value = ""
UserForm5.TextBox2.Value = ""
UserForm5.TextBox11.Value = ""
UserForm5.TextBox15.Value = ""
UserForm5.TextBox19.Value = ""
UserForm5.TextBox23.Value = ""
UserForm5.TextBox27.Value = ""
UserForm5.TextBox31.Value = ""
UserForm5.ComboBox1.Value = ""
UserForm5.ComboBox2.Value = ""
UserForm5.TextBox2.Value = ""
UserForm5.TextBox12.Value = ""
UserForm5.TextBox16.Value = ""
UserForm5.TextBox20.Value = ""
UserForm5.TextBox24.Value = ""
UserForm5.TextBox28.Value = ""
UserForm5.TextBox32.Value = ""
UserForm5.ComboBox1.Value = ""
UserForm5.ComboBox2.Value = ""
UserForm5.TextBox2.Value = ""
UserForm5.TextBox13.Value = ""
UserForm5.TextBox17.Value = ""
UserForm5.TextBox21.Value = ""
UserForm5.TextBox25.Value = ""
UserForm5.TextBox29.Value = ""
UserForm5.TextBox33.Value = ""
UserForm5.ComboBox1.Value = ""
UserForm5.ComboBox2.Value = ""
UserForm5.TextBox2.Value = ""
UserForm5.TextBox14.Value = ""
UserForm5.TextBox18.Value = ""
UserForm5.TextBox22.Value = ""
UserForm5.TextBox26.Value = ""
UserForm5.TextBox30.Value = ""
UserForm5.TextBox34.Value = ""
UserForm5.ComboBox1.Value = ""
UserForm5.ComboBox2.Value = ""
UserForm5.TextBox2.Value = ""
UserForm5.TextBox35.Value = ""
UserForm5.TextBox36.Value = ""
UserForm5.TextBox37.Value = ""
UserForm5.TextBox38.Value = ""
UserForm5.TextBox39.Value = ""
UserForm5.TextBox40.Value = ""
Call Refresh_Data
End Sub
Then there are a further 6 rows of 6 textboxes , if some of the 6 rows of textboxes are left blank, when Data is sent to the sheet via the Enter Button (CommandButton2) I need to prevent the empty textboxes being loaded onto the sheet
Below is the code I have to send data to sheet
Private Sub CommandButton2_Click()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Sheet3")
Dim Last_Row As Long
Last_Row = Application.WorksheetFunction.CountA(sh.Range("A:A"))
sh.Range("A" & Last_Row + 1).Value = "=Row()-1"
sh.Range("B" & Last_Row + 1).Value = Now
sh.Range("C" & Last_Row + 1).Value = UserForm5.ComboBox2.Value
sh.Range("D" & Last_Row + 1).Value = UserForm5.TextBox2.Value
sh.Range("E" & Last_Row + 1).Value = UserForm5.ComboBox1.Value
sh.Range("F" & Last_Row + 1).Value = UserForm5.TextBox3.Value
sh.Range("H" & Last_Row + 1).Value = UserForm5.TextBox5.Value
sh.Range("J" & Last_Row + 1).Value = UserForm5.TextBox7.Value
sh.Range("K" & Last_Row + 1).Value = UserForm5.TextBox8.Value
sh.Range("I" & Last_Row + 1).Value = UserForm5.TextBox6.Value
sh.Range("L" & Last_Row + 1).Value = UserForm5.TextBox10.Value
sh.Range("A" & Last_Row + 2).Value = "=Row()-1"
sh.Range("B" & Last_Row + 2).Value = Now
sh.Range("C" & Last_Row + 2).Value = UserForm5.ComboBox2.Value
sh.Range("D" & Last_Row + 2).Value = UserForm5.TextBox2.Value
sh.Range("E" & Last_Row + 2).Value = UserForm5.ComboBox1.Value
sh.Range("F" & Last_Row + 2).Value = UserForm5.TextBox11.Value
sh.Range("H" & Last_Row + 2).Value = UserForm5.TextBox15.Value
sh.Range("J" & Last_Row + 2).Value = UserForm5.TextBox19.Value
sh.Range("K" & Last_Row + 2).Value = UserForm5.TextBox23.Value
sh.Range("I" & Last_Row + 2).Value = UserForm5.TextBox27.Value
sh.Range("L" & Last_Row + 2).Value = UserForm5.TextBox31.Value
sh.Range("A" & Last_Row + 3).Value = "=Row()-1"
sh.Range("B" & Last_Row + 3).Value = Now
sh.Range("C" & Last_Row + 3).Value = UserForm5.ComboBox2.Value
sh.Range("D" & Last_Row + 3).Value = UserForm5.TextBox2.Value
sh.Range("E" & Last_Row + 3).Value = UserForm5.ComboBox1.Value
sh.Range("F" & Last_Row + 3).Value = UserForm5.TextBox12.Value
sh.Range("H" & Last_Row + 3).Value = UserForm5.TextBox16.Value
sh.Range("J" & Last_Row + 3).Value = UserForm5.TextBox20.Value
sh.Range("K" & Last_Row + 3).Value = UserForm5.TextBox24.Value
sh.Range("I" & Last_Row + 3).Value = UserForm5.TextBox28.Value
sh.Range("L" & Last_Row + 3).Value = UserForm5.TextBox32.Value
sh.Range("A" & Last_Row + 4).Value = "=Row()-1"
sh.Range("B" & Last_Row + 4).Value = Now
sh.Range("C" & Last_Row + 4).Value = UserForm5.ComboBox2.Value
sh.Range("D" & Last_Row + 4).Value = UserForm5.TextBox2.Value
sh.Range("E" & Last_Row + 4).Value = UserForm5.ComboBox1.Value
sh.Range("F" & Last_Row + 4).Value = UserForm5.TextBox13.Value
sh.Range("H" & Last_Row + 4).Value = UserForm5.TextBox17.Value
sh.Range("J" & Last_Row + 4).Value = UserForm5.TextBox21.Value
sh.Range("K" & Last_Row + 4).Value = UserForm5.TextBox25.Value
sh.Range("I" & Last_Row + 4).Value = UserForm5.TextBox29.Value
sh.Range("L" & Last_Row + 4).Value = UserForm5.TextBox33.Value
sh.Range("A" & Last_Row + 5).Value = "=Row()-1"
sh.Range("B" & Last_Row + 5).Value = Now
sh.Range("C" & Last_Row + 5).Value = UserForm5.ComboBox2.Value
sh.Range("D" & Last_Row + 5).Value = UserForm5.TextBox2.Value
sh.Range("E" & Last_Row + 5).Value = UserForm5.ComboBox1.Value
sh.Range("F" & Last_Row + 5).Value = UserForm5.TextBox14.Value
sh.Range("H" & Last_Row + 5).Value = UserForm5.TextBox18.Value
sh.Range("J" & Last_Row + 5).Value = UserForm5.TextBox22.Value
sh.Range("K" & Last_Row + 5).Value = UserForm5.TextBox26.Value
sh.Range("I" & Last_Row + 5).Value = UserForm5.TextBox30.Value
sh.Range("L" & Last_Row + 5).Value = UserForm5.TextBox34.Value
sh.Range("A" & Last_Row + 6).Value = "=Row()-1"
sh.Range("B" & Last_Row + 6).Value = Now
sh.Range("C" & Last_Row + 6).Value = UserForm5.ComboBox2.Value
sh.Range("D" & Last_Row + 6).Value = UserForm5.TextBox2.Value
sh.Range("E" & Last_Row + 6).Value = UserForm5.ComboBox1.Value
sh.Range("F" & Last_Row + 6).Value = UserForm5.TextBox35.Value
sh.Range("H" & Last_Row + 6).Value = UserForm5.TextBox36.Value
sh.Range("J" & Last_Row + 6).Value = UserForm5.TextBox37.Value
sh.Range("K" & Last_Row + 6).Value = UserForm5.TextBox38.Value
sh.Range("I" & Last_Row + 6).Value = UserForm5.TextBox39.Value
sh.Range("L" & Last_Row + 6).Value = UserForm5.TextBox40.Value
UserForm5.ComboBox1.Value = ""
UserForm5.ComboBox2.Value = ""
UserForm5.TextBox2.Value = ""
UserForm5.TextBox3.Value = ""
UserForm5.TextBox5.Value = ""
UserForm5.TextBox6.Value = ""
UserForm5.TextBox7.Value = ""
UserForm5.TextBox8.Value = ""
UserForm5.TextBox10.Value = ""
UserForm5.ComboBox1.Value = ""
UserForm5.ComboBox2.Value = ""
UserForm5.TextBox2.Value = ""
UserForm5.TextBox11.Value = ""
UserForm5.TextBox15.Value = ""
UserForm5.TextBox19.Value = ""
UserForm5.TextBox23.Value = ""
UserForm5.TextBox27.Value = ""
UserForm5.TextBox31.Value = ""
UserForm5.ComboBox1.Value = ""
UserForm5.ComboBox2.Value = ""
UserForm5.TextBox2.Value = ""
UserForm5.TextBox12.Value = ""
UserForm5.TextBox16.Value = ""
UserForm5.TextBox20.Value = ""
UserForm5.TextBox24.Value = ""
UserForm5.TextBox28.Value = ""
UserForm5.TextBox32.Value = ""
UserForm5.ComboBox1.Value = ""
UserForm5.ComboBox2.Value = ""
UserForm5.TextBox2.Value = ""
UserForm5.TextBox13.Value = ""
UserForm5.TextBox17.Value = ""
UserForm5.TextBox21.Value = ""
UserForm5.TextBox25.Value = ""
UserForm5.TextBox29.Value = ""
UserForm5.TextBox33.Value = ""
UserForm5.ComboBox1.Value = ""
UserForm5.ComboBox2.Value = ""
UserForm5.TextBox2.Value = ""
UserForm5.TextBox14.Value = ""
UserForm5.TextBox18.Value = ""
UserForm5.TextBox22.Value = ""
UserForm5.TextBox26.Value = ""
UserForm5.TextBox30.Value = ""
UserForm5.TextBox34.Value = ""
UserForm5.ComboBox1.Value = ""
UserForm5.ComboBox2.Value = ""
UserForm5.TextBox2.Value = ""
UserForm5.TextBox35.Value = ""
UserForm5.TextBox36.Value = ""
UserForm5.TextBox37.Value = ""
UserForm5.TextBox38.Value = ""
UserForm5.TextBox39.Value = ""
UserForm5.TextBox40.Value = ""
Call Refresh_Data
End Sub