LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 34
Default "bisecting" loop with boolean flags

Peter T and bz,

thanks for your input. Both are super elegant solutions. Thanks also for
helping me expand my knowledge of vb and programming logic in general.

Henrik


"bz" wrote:

?B?S3JhZ2VsdW5k?= wrote in
:

Help pls! I need a procedure which can help me to select a selection A
and B respectively, so that selection A is chosen every other time the
procedure runs (and the same for selection B). I intended to make a
procedure that sets the flag to TRUE when the flag is FALSE and vice
versa. In the code presented below, the boolean value remains FALSE and
never changes to TRUE.

What I am doing wrong??

Public Sub Insert_Flag()
Dim Worksheet As Worksheet
Dim Flg As Boolean

Set Worksheet = ActiveSheet

Select Case Flg

Case Flg = True (Selection A)
Flg = False
If Flg = False Then Cells(1, 3) = False

Case Flg = False (Selection B)
Flg = True
If Flg = True Then Cells(1, 3) = True

End Select

End Sub

I think your flag needs to be public so that it doesn't get re-initialized
between executions of your subroutine. I doubt that private variables
'exist' when the subroutine isn't active.

I think also that there is no guarantee that Flg will hold any specific
value the first time you run your routine (or it might be null).

You could use the contents of a cell in your workbook as your flag, if you
don't want a global variable. You could start with 1 or -1 and multiply it
by -1 every time your routine executes.




--
bz

please pardon my infinite ignorance, the set-of-things-I-do-not-know is an
infinite set.

remove ch100-5 to avoid spam trap

 
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
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
change "true" and "false" to "availble" and "out of stock" inthestands Excel Worksheet Functions 2 July 19th 07 07:05 PM
"acessor flags" creating pivot table from recordset Wolfie Excel Programming 1 April 12th 06 09:43 PM
Can a "flags" or "reminders" be used in a ws gidawie1 New Users to Excel 2 January 13th 06 02:16 PM
LOOP BETWEEN "FRONT" AND "END" SHEETS? ewan7279 Excel Programming 7 March 17th 05 03:11 PM


All times are GMT +1. The time now is 05:32 AM.

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"