david.paton
Registered User.
- Local time
- Yesterday, 21:40
- Joined
- Jun 26, 2013
- Messages
- 338
I have been asked by my boss to make a spreadsheet that is used for calculations. This spreadsheet has 3 lookup columns that change the calculations and 2 columns that measure units and number of workers required. These impact the price as well. I don't know how to code but I have managed to find some code that will delete rows. This is the code I have:
Sub Button6_Click()
Dim lastrow As Integer
lastrow = ActiveSheet.Range("table3").ListObject.Range.Rows.Count
ActiveSheet.Unprotect Password:="123"
Range("table3").ListObject.ListRows(lastrow - 1).Delete
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="123"
End Sub
I also have found some code to insert a new row too, but it won't copy formulas to the new cells.
Private Sub CommandButton2_Click()
Dim the_sheet As Worksheet
Dim table_list_object As ListObject
Dim table_object_row As ListRow
Set the_sheet = Sheets("Schedule 3 -Request for Service")
Set table_list_object = the_sheet.ListObjects(1)
Set table_object_row = table_list_object.ListRows.Add
End Sub
The only problem is that I have formulas in columns F, G, H and M that I need copied to the new row when it is created.
Could someone please help me with a way to add these formulas to these rows and also if there is a better way to accomplish the insert/delete rows.
In addition, the spreadsheet will be locked down so users can't change formulas or wreck it. How do I accomplish the above when the sheet is protected. I can't upload the spreadsheet for privacy reasons. I have been searching the net all weekend but I can't seem to find anything.
Thanks,
Dave
Sub Button6_Click()
Dim lastrow As Integer
lastrow = ActiveSheet.Range("table3").ListObject.Range.Rows.Count
ActiveSheet.Unprotect Password:="123"
Range("table3").ListObject.ListRows(lastrow - 1).Delete
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="123"
End Sub
I also have found some code to insert a new row too, but it won't copy formulas to the new cells.
Private Sub CommandButton2_Click()
Dim the_sheet As Worksheet
Dim table_list_object As ListObject
Dim table_object_row As ListRow
Set the_sheet = Sheets("Schedule 3 -Request for Service")
Set table_list_object = the_sheet.ListObjects(1)
Set table_object_row = table_list_object.ListRows.Add
End Sub
The only problem is that I have formulas in columns F, G, H and M that I need copied to the new row when it is created.
Could someone please help me with a way to add these formulas to these rows and also if there is a better way to accomplish the insert/delete rows.
In addition, the spreadsheet will be locked down so users can't change formulas or wreck it. How do I accomplish the above when the sheet is protected. I can't upload the spreadsheet for privacy reasons. I have been searching the net all weekend but I can't seem to find anything.
Thanks,
Dave