Hello MrExcel Forums!
First post, so please let me know if I am performing any forum faux pas on here. I searched/lurked through many threads but couldn't seem to find the answer I was looking for. I made an excel tool for some very not savvy excel people. It is protected and I'm building macros into buttons so they have some ability to alter the data tool in specific ways. Essentially, I'd like to give users the ability to insert rows, retaining formatting of formulas, and the ability to choose where they want to insert the row. This is my code so far:
Private Sub CommandButton1_Click()
Dim rowNum As Integer
On Error Resume Next
rowNum = Application.InputBox(Prompt:="Enter Row Number where you want to add a row:", _
Title:="Insert New Row", Type:=1)
Unprotect Password:="M"
Rows(rowNum & ":" & rowNum).Copy
Rows(rowNum & ":" & rowNum).Insert Shift:=xlDown
Protect Password:="M"
End Sub
I have a header (Rows 1-3) and a footer (currently Rows 36-40, but that range will change every time a row is added) that I need to remain protected and shouldn't be copied/touched. I've named the header and footer range as one unit (HeaderFooter, rows 1-3 &36-40) in Excel and have been trying to figure out how to exclude any row selection that sits in that range (i.e. if someone were to type in to add a row at "36", for the macro to not perform the copy/insert) or to only allow selections within another named range I created (DataSet, rows 4-35).
Would anyone be able to provide me with some guidance? Thank you so very much in advance!
First post, so please let me know if I am performing any forum faux pas on here. I searched/lurked through many threads but couldn't seem to find the answer I was looking for. I made an excel tool for some very not savvy excel people. It is protected and I'm building macros into buttons so they have some ability to alter the data tool in specific ways. Essentially, I'd like to give users the ability to insert rows, retaining formatting of formulas, and the ability to choose where they want to insert the row. This is my code so far:
Private Sub CommandButton1_Click()
Dim rowNum As Integer
On Error Resume Next
rowNum = Application.InputBox(Prompt:="Enter Row Number where you want to add a row:", _
Title:="Insert New Row", Type:=1)
Unprotect Password:="M"
Rows(rowNum & ":" & rowNum).Copy
Rows(rowNum & ":" & rowNum).Insert Shift:=xlDown
Protect Password:="M"
End Sub
I have a header (Rows 1-3) and a footer (currently Rows 36-40, but that range will change every time a row is added) that I need to remain protected and shouldn't be copied/touched. I've named the header and footer range as one unit (HeaderFooter, rows 1-3 &36-40) in Excel and have been trying to figure out how to exclude any row selection that sits in that range (i.e. if someone were to type in to add a row at "36", for the macro to not perform the copy/insert) or to only allow selections within another named range I created (DataSet, rows 4-35).
Would anyone be able to provide me with some guidance? Thank you so very much in advance!