View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
JE McGimpsey JE McGimpsey is offline
external usenet poster
 
Posts: 4,624
Default True / false statements in Macros

Assuming you're talking about a forms toolbar checkbox, one way:

Assign this macro to the checkbox (right-click the checkbox and choose
Assign Macro):

Public Sub CheckBox1_Click()
Const sSHEETNAME As String = "My New Sheet"
On Error Resume Next
With ActiveSheet
If .CheckBoxes(Application.Caller).Value = xlOn Then
With Worksheets.Add(After:=Sheets(Sheets.Count))
.Name = sSHEETNAME
.Range("A1").Value = "Related Text"
End With
.Select 'Restore selection to calling sheet
Else
Application.DisplayAlerts = False
Worksheets(sSHEETNAME).Delete
Application.DisplayAlerts = True
End If
End With
On Error GoTo 0
End Sub


No need to have a linked cell unless it serves some other purpose.

In article ,
"RogerNZ" wrote:

I would like to set up a tick box to work like a toggle function.
Specifically so that when it is ticked it activates a macro to insert a new
sheet and related text, when it is then unticked it deletes the sheet from
the workbook. I have been dabling in Excel Macros for a while now, but I
haven't had any serious training so anything beyond what I can pick up out of
seeing what the macro recorder does is a little mistifying. Mainly what I was
hoping for is a sample of a Macro that checks a cell value for true or false
value to determine which section of the macro to run, so that I can assign a
single macro to the tick box and cell link the tick box to give a true or
false value which will be used as above to determine which section of the
macro to run. Of course if there is an easier way....