LeahWright
New Member
- Joined
- Jun 14, 2004
- Messages
- 39
- Office Version
- 365
I am working on a timesheet that will allow the user to input data, but not change certain cells. I have two buttons built into the worksheet: one to delete a row and one to insert a row. The buttons delete and insert in relation to the location of the active cell.
My problem: I am getting 1004 errors, as well as others at other times.
Since the line I want to insert involves specific formatting and merging, I thought the easiest way to go about this would be to make a "line master" worksheet and copy the line from the line master and insert it into the input sheet.
Ideally:
Insert Button:
1. User clicks a cell in the row on ws."Input" where they want the new row to appear.
2. Unprotect (with password) ws."Line Master" and ws."Input"
3. Unhide ws."Line Master"
4. Copy Row 1:1 from ws."Line Master"
5. Go back to ws."Input" and insert the copied row at the location of the ActiveCell from Step 1
6. Hide ws."Line Master"
7. Protect (with password) ws."Line Master" and ws."Input"
My code: (I was having problems, so I stripped the protect/unprotect/hide/unhide lines from the code and went back to basics.)
Delete Button:
1. User clicks a cell in the row on ws."Input" they want to delete.
2. Unprotect (with password) ws."Input"
3. Delete the row.
4. Protect (with password) ws."Input"
The delete code I'm currently using, thanks to MrExcel.com : (Except for the lack of protect/hide code, it seems to be working perfectly.)
Can someone please help? I want to be able to protect/hide but still allow the user to add/delete lines by using the buttons I've supplied (but not the menus). I can't seem to tie the protection lines in with the rest of my code and make it work.
My problem: I am getting 1004 errors, as well as others at other times.
Since the line I want to insert involves specific formatting and merging, I thought the easiest way to go about this would be to make a "line master" worksheet and copy the line from the line master and insert it into the input sheet.
Ideally:
Insert Button:
1. User clicks a cell in the row on ws."Input" where they want the new row to appear.
2. Unprotect (with password) ws."Line Master" and ws."Input"
3. Unhide ws."Line Master"
4. Copy Row 1:1 from ws."Line Master"
5. Go back to ws."Input" and insert the copied row at the location of the ActiveCell from Step 1
6. Hide ws."Line Master"
7. Protect (with password) ws."Line Master" and ws."Input"
My code: (I was having problems, so I stripped the protect/unprotect/hide/unhide lines from the code and went back to basics.)
Code:
Sub InsertRow()
Sheets("Line Master").Select
Rows("1:1").Select
Selection.Copy
Sheets("Input").Select
Rows(ActiveCell.Row).Insert Shift:=xlDown
Delete Button:
1. User clicks a cell in the row on ws."Input" they want to delete.
2. Unprotect (with password) ws."Input"
3. Delete the row.
4. Protect (with password) ws."Input"
The delete code I'm currently using, thanks to MrExcel.com : (Except for the lack of protect/hide code, it seems to be working perfectly.)
Code:
Sub delete_row()
'Erik Van Geit
'050608 0041
'to delete rows when sheet is protected
Dim nrs As String
If Selection.Rows.Count = 1 Then
nrs = "row " & Selection.Row
Else
nrs = "rows " & Application.WorksheetFunction.Substitute(Selection.EntireRow.Address(0, 0), ":", " to ")
End If
ActiveSheet.Unprotect
If MsgBox("Do you want to delete " & nrs & "?", 36, "DELETE ROWS") = vbNo Then Exit Sub
Selection.EntireRow.Delete
ActiveSheet.Protect
End Sub
Can someone please help? I want to be able to protect/hide but still allow the user to add/delete lines by using the buttons I've supplied (but not the menus). I can't seem to tie the protection lines in with the rest of my code and make it work.
Last edited: