Hi Guys,
How can I toggle this macro on a button click?
Thanks in advance![]()
Sub Button1_ToggleforEdit() ActiveSheet.Unprotect Range("B2").Select ActiveSheet.ListObjects("List1").Unlist End Sub
Hi Guys,
How can I toggle this macro on a button click?
Thanks in advance![]()
Sub Button1_ToggleforEdit() ActiveSheet.Unprotect Range("B2").Select ActiveSheet.ListObjects("List1").Unlist End Sub
Toggle it to do what?
Hi Baziwan;
I don't know anything about ListObjects. I'm going to try and learn about them.
But something like this should do what you want.
I would really like to see the finished macro, so when you have fixed mine, please post it back here.![]()
Sub Button1_ToggleforEdit() Dim v Dim lErr as Long On Error Resume Next v = ActiveSheet.ListObjects("List1").Name lErr = Err.Number On Error Goto 0 If lErr = 0 Then ActiveSheet.Unprotect Range("B2").Select ActiveSheet.ListObjects("List1").Unlist Else 'I don't know how to create a ListObject with macros ' so change this line to do what you want With ActiveSheet.ListObjects.Add .Name = "List1" End With ActiveSheet.Protect End If End Sub
Why not do it all at once?
Add a button from the Controls ToolBox then use this code
![]()
Private Sub CommandButton1_Click() With Me .Unprotect If .CommandButton1.Caption = "List Off" Then .ListObjects("List1").Unlist .CommandButton1.Caption = "List On" Else: .ListObjects.Add(xlSrcRange, Range("B6").CurrentRegion, , xlYes).Name _ = "List1" Application.CommandBars("List").Visible = False .CommandButton1.Caption = "List Off" End If .Protect End With End Sub
Hope that helps.
RoyUK
--------
For Excel Tips & Solutions, free examples and tutorials why not check out my web site
Free DataBaseForm example
Hi Roy;
I really like your idea of changing the caption on the Button.
What's the purpose of this line?
I'm using XL2002, so I don't have ListObjects, but I'd like to know why you hide it.![]()
Application.CommandBars("List").Visible = False
That line switches off the List Toolbar, it's not essential.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks