Hi all,
I have two tables on one spreadsheet (LiveProjects and TenderProjects) and I wish for a new row to be added with the data entered from the UserForm. The coding I have done for this works but what I particularly need is that depending on the 'Status' selected from the StatusListBox, the new row is added to either the LiveProjects table or the TenderProjects table.
If "Secured", "Live" or "Completed" is selected then the new row must be added to the "LiveProjects" table
Else if "Tender Negotiated", "Tender (Favourable)" or "Tender (Pipeline)" selected the new row needs to be added to the TenderProjects table.
Below is the code I am stuck with at the moment:
Private Sub AddNewButton_Click()
Dim the_sheet As Worksheet
Dim table_list_object As ListObject
Dim table_object_row As ListRow
Set the_sheet = Sheets("Data Sheet")
Set table_list_object = the_sheet.ListObjects("LiveProjects", "TenderProjects")
Set table_object_row = table_list_object.ListRows.Add
If StatusListBox.Value = "Secured" & "Live" & "Completed" Then
ListObjects = "LiveProjects"
Else
ListObjects = "TenderProjects"
End If
table_object_row.Range(1, 1).Value = ProjectNameTextBox.Value
last_row_with_data = the_sheet.Range("A65536").End(xlUp).Row
last_row_with_data = last_row_with_data
the_sheet.Range("B" & last_row_with_data) = ClientTextBox.Value
the_sheet.Range("C" & last_row_with_data) = SectorListBox.Value
the_sheet.Range("D" & last_row_with_data) = StatusListBox.Value
the_sheet.Range("E" & last_row_with_data) = ContractValueTextBox.Value
the_sheet.Range("F" & last_row_with_data) = AFATextBox.Value
the_sheet.Range("G" & last_row_with_data) = RTPTextBox.Value
the_sheet.Range("H" & last_row_with_data) = TwentyFifteenTextBox.Value
the_sheet.Range("I" & last_row_with_data) = TwentySixteenTextBox.Value
the_sheet.Range("J" & last_row_with_data) = TwentySeventeenTextBox.Value
the_sheet.Range("K" & last_row_with_data) = TwentyEighteenTextBox.Value
the_sheet.Range("L" & last_row_with_data) = TwentyNineteenTextBox.Value
the_sheet.Range("M" & last_row_with_data) = DisciplineListBox.Value
the_sheet.Range("N" & last_row_with_data) = BoardDirectorListBox.Value
the_sheet.Range("O" & last_row_with_data) = AssociateDirectorTextBox.Value
the_sheet.Range("P" & last_row_with_data) = CommercialManagerTextBox.Value
the_sheet.Range("Q" & last_row_with_data) = ProjectManagerTextBox.Value
the_sheet.Range("R" & last_row_with_data) = QuantitySurveyorTextBox.Value
the_sheet.Range("S" & last_row_with_data) = PreConTextBox.Value
the_sheet.Range("T" & last_row_with_data) = ActualTextBox.Value
the_sheet.Range("U" & last_row_with_data) = DPStartTextBox.Value
the_sheet.Range("V" & last_row_with_data) = DPEndTextBox.Value
If Me.ProjectNameTextBox.Value = "" Then
MsgBox "Please enter Project Name.", vbExclamation, "Project Tracker Template"
Me.ProjectNameTextBox.SetFocus
End If
End Sub
As I said, the adding a new row part works, I just need to make it so the new row is added to a particular table according to the status selected.
Hope this makes sense and someone can help.
I have two tables on one spreadsheet (LiveProjects and TenderProjects) and I wish for a new row to be added with the data entered from the UserForm. The coding I have done for this works but what I particularly need is that depending on the 'Status' selected from the StatusListBox, the new row is added to either the LiveProjects table or the TenderProjects table.
If "Secured", "Live" or "Completed" is selected then the new row must be added to the "LiveProjects" table
Else if "Tender Negotiated", "Tender (Favourable)" or "Tender (Pipeline)" selected the new row needs to be added to the TenderProjects table.
Below is the code I am stuck with at the moment:
Private Sub AddNewButton_Click()
Dim the_sheet As Worksheet
Dim table_list_object As ListObject
Dim table_object_row As ListRow
Set the_sheet = Sheets("Data Sheet")
Set table_list_object = the_sheet.ListObjects("LiveProjects", "TenderProjects")
Set table_object_row = table_list_object.ListRows.Add
If StatusListBox.Value = "Secured" & "Live" & "Completed" Then
ListObjects = "LiveProjects"
Else
ListObjects = "TenderProjects"
End If
table_object_row.Range(1, 1).Value = ProjectNameTextBox.Value
last_row_with_data = the_sheet.Range("A65536").End(xlUp).Row
last_row_with_data = last_row_with_data
the_sheet.Range("B" & last_row_with_data) = ClientTextBox.Value
the_sheet.Range("C" & last_row_with_data) = SectorListBox.Value
the_sheet.Range("D" & last_row_with_data) = StatusListBox.Value
the_sheet.Range("E" & last_row_with_data) = ContractValueTextBox.Value
the_sheet.Range("F" & last_row_with_data) = AFATextBox.Value
the_sheet.Range("G" & last_row_with_data) = RTPTextBox.Value
the_sheet.Range("H" & last_row_with_data) = TwentyFifteenTextBox.Value
the_sheet.Range("I" & last_row_with_data) = TwentySixteenTextBox.Value
the_sheet.Range("J" & last_row_with_data) = TwentySeventeenTextBox.Value
the_sheet.Range("K" & last_row_with_data) = TwentyEighteenTextBox.Value
the_sheet.Range("L" & last_row_with_data) = TwentyNineteenTextBox.Value
the_sheet.Range("M" & last_row_with_data) = DisciplineListBox.Value
the_sheet.Range("N" & last_row_with_data) = BoardDirectorListBox.Value
the_sheet.Range("O" & last_row_with_data) = AssociateDirectorTextBox.Value
the_sheet.Range("P" & last_row_with_data) = CommercialManagerTextBox.Value
the_sheet.Range("Q" & last_row_with_data) = ProjectManagerTextBox.Value
the_sheet.Range("R" & last_row_with_data) = QuantitySurveyorTextBox.Value
the_sheet.Range("S" & last_row_with_data) = PreConTextBox.Value
the_sheet.Range("T" & last_row_with_data) = ActualTextBox.Value
the_sheet.Range("U" & last_row_with_data) = DPStartTextBox.Value
the_sheet.Range("V" & last_row_with_data) = DPEndTextBox.Value
If Me.ProjectNameTextBox.Value = "" Then
MsgBox "Please enter Project Name.", vbExclamation, "Project Tracker Template"
Me.ProjectNameTextBox.SetFocus
End If
End Sub
As I said, the adding a new row part works, I just need to make it so the new row is added to a particular table according to the status selected.
Hope this makes sense and someone can help.