bridgetd15
New Member
- Joined
- Aug 11, 2022
- Messages
- 5
- Office Version
- 365
- Platform
- Windows
I have an excel sheet that many people will be using so it is locked. I am trying to add a button to add lines in a section. I have the button working to add a line but when you hit the button again, it does it for the same row. I'd like it to add a row at the bottom of the section each time so the first row is inserted at row 12 and the next row would be inserted in row 13 then row 14 and so on (hope this makes sense). The inserted row is then copied from the row above it to include the formulas. Below is what is written for the button (I used google for help to get to this point as I haven't worked in VBA in many years).
Private Sub AddLaborLine_Click()
Application.ScreenUpdating = False
Dim xSheet As Worksheet
Set xSheet = ActiveSheet
If xSheet.Name <> "Definitions" And xSheet.Name <> "fx" And xSheet.Name <> "Needs" Then
xSheet.Range("A12:R12").Insert
xSheet.Range("A11:R11 ").Copy
xSheet.Range("A12:R12").PasteSpecial Paste:=xlFormulas, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End If
Application.ScreenUpdating = True
End Sub
I have tried adding Loop, Next, and anything else I could find to possibly help on google. I've tried so many different things and can't get it to work. Is this possible to do? If so, what do I need to do to accomplish it? This is just the code for the button to work on the same line. I didn't include anything I've tried to try to loop it to the next line.
Thanks!
Private Sub AddLaborLine_Click()
Application.ScreenUpdating = False
Dim xSheet As Worksheet
Set xSheet = ActiveSheet
If xSheet.Name <> "Definitions" And xSheet.Name <> "fx" And xSheet.Name <> "Needs" Then
xSheet.Range("A12:R12").Insert
xSheet.Range("A11:R11 ").Copy
xSheet.Range("A12:R12").PasteSpecial Paste:=xlFormulas, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End If
Application.ScreenUpdating = True
End Sub
I have tried adding Loop, Next, and anything else I could find to possibly help on google. I've tried so many different things and can't get it to work. Is this possible to do? If so, what do I need to do to accomplish it? This is just the code for the button to work on the same line. I didn't include anything I've tried to try to loop it to the next line.
Thanks!