Re: General Novice Questions (Protection, Format) by Earl
Earl
Sat May 10 13:29:13 CDT 2008
Greg,
Here are the macros. Put them in a regular module, and assign them to keyboard shortcuts, if
desired (Tools - Macros - Macros - Options). Or put a buttons on the sheet (drawing
toolbar), and assign them to the macros.
Sub InsertRow()
If ActiveCell.Locked = True Then
MsgBox "You can't insert a row here", vbOKOnly, ""
Exit Sub
End If
ActiveSheet.Unprotect Password:="aa"
ActiveCell.EntireRow.Insert
ActiveSheet.Protect Password:="aa"
End Sub
Sub DeleteRow()
If ActiveCell.Locked = True Then
MsgBox "You can't remove a row here", vbOKOnly, ""
Exit Sub
End If
ActiveSheet.Unprotect Password:="aa"
ActiveCell.EntireRow.Delete
ActiveSheet.Protect Password:="aa"
End Sub
These routines will allow inserting/deleting rows based on the active cell being protected.
If there are other cells in the sheet that are unprotected, they'll allow
inserting/deleting, which is undesirable. If there are such other cells, we'll need another
means of checking. Post back if that's the case.
If you're not using passwords in your sheet protection, remove the Password:="aa" part.
--
Regards from Virginia Beach,
Earl Kiosterud
www.smokeylake.com
-----------------------------------------------------------------------
"Greg" <ApexData@gmail.com> wrote in message
news:5083b55c-66ac-415c-8e04-6c57ffaf09cb@x41g2000hsb.googlegroups.com...
I have programmed with MS Access frequently and am familiar with VBA.
Can you give sample code for a button to Add and one for Del and how
to go about it.
I think once I see it, I'll be on the way to getting this
accomplished.
Thanks Again
Greg
On May 10, 12:20 pm, "Earl Kiosterud" <some...@nowhere.com> wrote:
> Greg,
>
> Once the worksheet is protected, as you know, inserting is disallowed. Drag-moving is
> allowed, but should not be used if there are formulas in the worksheet, as it's possible
> that the formulas will change as a result of the move. Drag-moving is a design tool, not a
> data entry tool.
>
> The best way would be to have a macro available for the user. It would unprotect the
> sheet,
> insert the new row (perhaps where the active cell is currently), then re--protect the
> sheet.
> The macro could be invoked by a button, a keyboard shortcut, or even a new menu item.
> You'd
> probably also want a macro to remove a row, in the event that a user adds a row, then
> later
> doesn't want it.
>
> We can write the macro for you if you're able to put a macro in your sheet. You can bone
> up
> on how to work with macros it atwww.mcgimpsey.comif you're interested. Post back for the
> macro code.
> --
> Regards from Virginia Beach,
>
> Earl Kiosterudwww.smokeylake.com
>
> -----------------------------------------------------------------------"Greg"
> <ApexD...@gmail.com> wrote in message
>
> news:777925a9-d63d-4b2a-b1f1-c56c16266bd8@j22g2000hsf.googlegroups.com...
>
>
>
> >I have created a spreadsheet and have restricted a row and footing row
> > (totals) from being changed by using the "format cells / protection"
> > feature. I have left all the data entry rows
> > unprotected so that the entry people can make changes. These entry
> > rows have columns with specfics formats like Date, Currency, etc and I
> > make it all look nice with the grid feature. Finally,
> > I set "Tools /Protection/ Protect sheet" to active the protected
> > cells.
>
> > The problem is how can the user Insert new rows?
> > To get around this, I created enough rows so that the user has the
> > space they need (50 rows) to accomodate the necessary entries. The
> > new problem is that if the user forgets to make any entry they have to
> > Insert which they cannot do because of the protection. So, to get
> > around this they can drag the lower existing data rows down, but then
> > the opening they create loses the format that I set for that column
> > and the nice grid I put in disappears in those rows?
>
> > Any tips?
>
> > Thanks- Hide quoted text -
>
> - Show quoted text -