Hi all,
I'm trying to set up "protection" on my sheets, and so far sheet.protect doesn't do the job, because I have tables and I don't want my users to be able to add columns to the tables but AllowInsertingColumns = False still allows table columns to be added. So I think I have a solution, only I am not that good in VBA yet to be able to implement it... or to be exact I would rather not copy a code then change a few bits and be surprised if it does something unexpected because I didn't understand it to begin with..
So on Sheet4, I have a table in A10:M30 not including the headers, this is the range that doesn't need protection, my users need to be able to add and delete rows and change data in the cells, but at the same time this is the range they are not allowed to add columns to.
My idea is to use Workbook_SheetChange, because I have 4 sheets, and based on which sheet it is a different range needs protection, and this way it would be all in one place.. but if thats a bad idea please do tell and explain!
So on Sheet4, A9:M9 is my header row range, and I would make that the Target, and do a quick loop, count the cells in this range, and if its not 13 then (the user tried to add or delete a column) which is not allowed so: application.undo msgbox "You are not allowed to do that"
but I don't understand the syntax of this Workbook_SheetChange event... Sh is the sheet it is referring to.. the Activesheet, or can I specify
Sh = Sheet4? Or does that need to be part of an if block? Like: If Sh=Sheet4 then Target = Sheet4.Range("A9:M9") then do the loop if the count is not 13 then undo end if end if? Or how does this work??
Target is the Range I'm asking it to keep an eye on, so if that range changes then this code runs.. but how do I Dimension that Target (range)?
I can see this:
on many websites but I am so confused by this line... why intersect? Intersecting the Target (you specify?) with the Target(you specify??), and if it IS nothing then the code wouldn't trigger at all, so why is "If Not .... Is Nothing" necessary here?
Can someone explain how does this work please?
Thank you!
I'm trying to set up "protection" on my sheets, and so far sheet.protect doesn't do the job, because I have tables and I don't want my users to be able to add columns to the tables but AllowInsertingColumns = False still allows table columns to be added. So I think I have a solution, only I am not that good in VBA yet to be able to implement it... or to be exact I would rather not copy a code then change a few bits and be surprised if it does something unexpected because I didn't understand it to begin with..
So on Sheet4, I have a table in A10:M30 not including the headers, this is the range that doesn't need protection, my users need to be able to add and delete rows and change data in the cells, but at the same time this is the range they are not allowed to add columns to.
My idea is to use Workbook_SheetChange, because I have 4 sheets, and based on which sheet it is a different range needs protection, and this way it would be all in one place.. but if thats a bad idea please do tell and explain!
So on Sheet4, A9:M9 is my header row range, and I would make that the Target, and do a quick loop, count the cells in this range, and if its not 13 then (the user tried to add or delete a column) which is not allowed so: application.undo msgbox "You are not allowed to do that"
but I don't understand the syntax of this Workbook_SheetChange event... Sh is the sheet it is referring to.. the Activesheet, or can I specify
Sh = Sheet4? Or does that need to be part of an if block? Like: If Sh=Sheet4 then Target = Sheet4.Range("A9:M9") then do the loop if the count is not 13 then undo end if end if? Or how does this work??
Target is the Range I'm asking it to keep an eye on, so if that range changes then this code runs.. but how do I Dimension that Target (range)?
I can see this:
Code:
If Not Intersect(Target, Target.Worksheet.Range("your range here")) Is Nothing Then
on many websites but I am so confused by this line... why intersect? Intersecting the Target (you specify?) with the Target(you specify??), and if it IS nothing then the code wouldn't trigger at all, so why is "If Not .... Is Nothing" necessary here?
Can someone explain how does this work please?
Thank you!