Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default True / false statements in Macros

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....
--
Roger W
  #2   Report Post  
Posted to microsoft.public.excel.programming
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....

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default True / false statements in Macros

Thank you very much, I knew it was possible but just not how to make it execute.
--
Roger W


"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....
--
Roger W

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default True / false statements in Macros

OK, further to this, if I want to break down this macro to toggle other functions, how does it actually work.
The creation and deletion of the new sheet is very quick, however when I open my other spreadsheet to copy it across into the new sheet it becomes very slow.
My main aim was to insert a new sheet as per the Macro, but then to open my data sheet and copy it across and input customer details etc into the corresponding cells. The end result sheet has several of these tick boxes, when I tick them I wanted the program to open the worksheets required and copy them across into the current worksheet and copy the common data onto the new sheet, thus meaning that when I close the Header sheet I can save as required file name with only the relevant sheets attached. This would mean that I could update the copied worksheets separately and that my main header sheet file size would not be so large.
My other option would be to create a header sheet with all possible sheets and delete unrequired sheets according to the tick boxes (un)selected ie only keep sheets related to checked tick boxes.
--
Roger W


"JE McGimpsey" wrote:

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....


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Dates with true and false statements Princess V[_2_] Excel Discussion (Misc queries) 7 September 1st 09 07:59 PM
Assign different macros for True/False button Ken G. Excel Discussion (Misc queries) 2 April 3rd 09 04:50 AM
What's the best way to toggle between true and false in Excel? Hiall, My excel work involves a lot of toggling between true and false (booleantypes) ... and it's very repetitive... Is there a way to select a bunch ofcells, and press a key short-cu LunaMoon Excel Discussion (Misc queries) 9 July 29th 08 12:28 AM
Function to return True/False if all are validated as True by ISNU Tetsuya Oguma Excel Worksheet Functions 2 March 15th 06 10:28 AM
True Or False, no matter what... it still displays the false statement rocky640[_2_] Excel Programming 2 May 13th 04 04:57 PM


All times are GMT +1. The time now is 09:24 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"