Hi All, </SPAN>
The below code “CMD_Add_Click” allows me to fill in a user form and have the data enter into Sheet “Main” on the first empty row based on column 2 in total the code works great.
</SPAN>
I need to add a new user form that will allow me to do the following but I am totally stuck.
</SPAN>
What I need to do now is to input additional items on an existing row (not the next empty one) based on the matching value of Combox3. to column 6 on sheets "Main". There should never be any duplicates or repeating values in column 6. I was hoping it would be a simple edit to the below code that I have identified in red.
</SPAN>
Thank you in advance any suggestion or help would be greatly appreciated.
I apologize in advance for not using specific identifiers for text boxes I got carried away and was too far along to correct the generic names so go ahead and laugh. </SPAN>
Below is my full code for entering data to the data to the next empty line works well is set in a command button on the use of form.
The below code “CMD_Add_Click” allows me to fill in a user form and have the data enter into Sheet “Main” on the first empty row based on column 2 in total the code works great.
</SPAN>
I need to add a new user form that will allow me to do the following but I am totally stuck.
</SPAN>
What I need to do now is to input additional items on an existing row (not the next empty one) based on the matching value of Combox3. to column 6 on sheets "Main". There should never be any duplicates or repeating values in column 6. I was hoping it would be a simple edit to the below code that I have identified in red.
</SPAN>
Thank you in advance any suggestion or help would be greatly appreciated.
I apologize in advance for not using specific identifiers for text boxes I got carried away and was too far along to correct the generic names so go ahead and laugh. </SPAN>
Code:
‘Finds Next empty line in row 2 works great </SPAN>
[COLOR=#ff0000]iRow = ws.Cells(Rows.Count, 2) _[/COLOR]</SPAN>[COLOR=#ff0000]
.End(xlUp).Offset(1, 0).Row[/COLOR]</SPAN>[COLOR=#ff0000]
[/COLOR]
Code:
‘This was one of my attempts trying to fine a specific row Based on the value of textbox3 no this did not work I tried 100 versions of it NO GO!!!!!</SPAN>
iRow = ws.Cells(combobox3.value, 2) _</SPAN>
.End(xlUp).Offset(0, 0).Row</SPAN>
Below is my full code for entering data to the data to the next empty line works well is set in a command button on the use of form.
Code:
Private Sub CMD_Add_Click()
Dim rNextCl As Range
Set rNextCl = Worksheets("Main").Cells(Rows.Count, 2).End(xlUp).Offset(2, 0)
Worksheets("Main").Activate
rNextCl.Select
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Main")
ActiveSheet.Unprotect
'find first empty row in database
[COLOR=#ff0000]iRow = ws.Cells(Rows.Count, 2) _
.End(xlUp).Offset(1, 0).Row[/COLOR]
'check for a needed textbox data
If Me.edate1 = "" Or Me.ComboBox1 = "" Or Me.TextBox1 = "" Or Me.TextBox2 = "" _
Or Me.TextBox3 = "" Or Me.TextBox4 = "" Or Me.TextBox5 = "" Or Me.ComboBox2 = "" _
Or Me.TextBox6 = "" Or Me.TextBox7 = "" Or Me.TextBox8 = "" Then
MsgBox ("All Fields Must be Completed")
Exit Sub
End If
'copy the data to the database Sheets "Main"
With ws
.Cells(iRow, 2).Value = Me.edate1.Value
.Cells(iRow, 3).Value = Me.ComboBox1.Value
.Cells(iRow, 4).Value = Me.TextBox1.Value
.Cells(iRow, 5).Value = Me.TextBox2.Value
.Cells(iRow, 6).Value = Me.TextBox3.Value
.Cells(iRow, 7).Value = Me.TextBox4.Value
.Cells(iRow, 8).Value = Me.TextBox5.Value
.Cells(iRow, 9).Value = Me.ComboBox2.Value
.Cells(iRow, 10).Value = Me.TextBox6.Value
.Cells(iRow, 11).Value = Me.TextBox7.Value
.Cells(iRow, 12).Value = Me.TextBox8.Value
.Cells(iRow, 13).Value = Me.TextBox10.Value
.Cells(iRow, 14).Value = Me.TextBox11.Value
.Cells(iRow, 15).Value = Me.TextBox9.Value
'Add Border
With .Cells(iRow, 1).Resize(1, 15).Borders
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
'Add one to column "A" for the line item number
ws.Cells(iRow, 1).Value = ws.Cells(iRow - 1, 1).Value + 1
'clear the data in text and combo boxes after entry
Me.edate1.Value = ""
Me.ComboBox1.Value = ""
Me.TextBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
Me.TextBox4.Value = ""
Me.TextBox5.Value = ""
Me.ComboBox2.Value = ""
Me.TextBox6.Value = ""
Me.TextBox7.Value = ""
Me.TextBox8.Value = ""
Me.ComboBox3.Value = ""
Me.ComboBox4.Value = ""
Me.ComboBox5.Value = ""
Me.ComboBox6.Value = ""
Me.ComboBox7.Value = ""
Me.ComboBox8.Value = ""
Me.TextBox9.Value = ""
Me.TextBox12.Value = ""
Me.TextBox13.Value = ""
Me.TextBox16.Value = ""
Me.TextBox19.Value = ""
Me.TextBox20.Value = ""
Me.TextBox21.Value = ""
Me.TextBox22.Value = ""
Me.TextBox23.Value = ""
Me.TextBox24.Value = ""
Me.TextBox25.Value = ""
Me.TextBox26.Value = ""
Me.TextBox27.Value = ""
'Adds date in userform ready for next entry
edate1.Value = Now
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowSorting:=True, AllowFiltering:=True, AllowUsingPivotTables:=True
End With
'Set Option button 2 to no
OptionButton2.Value = True
'Set Option button to no
OptionButton4.Value = True
End Sub
Last edited: