For first question, here's the complete code you were talking about?
Code:
Sub RowInsert()
Set changeRng = GetRange
With changeRng
.Copy
.INSERT shift:=xlShiftDown
Range("A1").INSERT shift:=xlShiftDown
.Offset(-1).Locked = True
'If you want the new row to be blank, uncomment this line
'.Offset(-1).ClearContents
End With
Application.CutCopyMode = False
Call LockSheet
End Sub
if you want the new row to be blank, need to uncomment the next line with the Clear contents, to make the whole thing look like
Code:
Sub RowInsert()
Set changeRng = GetRange
With changeRng
.Copy
.INSERT shift:=xlShiftDown
Range("A1").INSERT shift:=xlShiftDown
.Offset(-1).Locked = True
'If you want the new row to be blank, uncomment this line
.Offset(-1).ClearContents
End With
Application.CutCopyMode = False
Call LockSheet
End Sub
For your 2nd question, my guess as to why it doesn't work would be to first check the Table name. If that's wrong, it won't work. Beyond that though, we can make things better/more robust with a few changes (this first one is my mistake). Since we already defined tb as our table, we should never have to do the long way. So, it should be:
Code:
Set tb = ActiveSheet.ListObjects("TaskList")
With ActiveSheet
'Check if user has selection within table
On Error Resume Next
Set myCell = Intersect(Selection, tb.DataBodyRange).Cells(1, 1)
Note how tb is used in the last line?
But, you mention that you want to use this button on multiple sheets. Would be nice if we could just write 1 code, instead of having multiple for all the different names. Assuming that you only have one table, or at least it's the left/top most on on the sheet, we can use the index number rather than the name.
Code:
Set tb = ActiveSheet.ListObjects(1)
With ActiveSheet
'Check if user has selection within table
On Error Resume Next
Set myCell = Intersect(Selection, tb.DataBodyRange).Cells(1, 1)
Now our code will work no matter what we name the table (at least, assuming there
is table in the worksheet.