+ Reply to Thread
Results 1 to 11 of 11

how to skip a boolean checkbox

Hybrid View

dmcgov how to skip a boolean checkbox 05-01-2019, 09:24 AM
protonLeah Re: how to skip a boolean... 05-01-2019, 09:51 PM
dmcgov Re: how to skip a boolean... 05-02-2019, 06:29 AM
Greg M Re: how to skip a boolean... 05-02-2019, 06:45 AM
Greg M Re: how to skip a boolean... 05-02-2019, 06:54 AM
dmcgov Re: how to skip a boolean... 05-02-2019, 10:00 AM
Greg M Re: how to skip a boolean... 05-02-2019, 10:20 AM
dmcgov Re: how to skip a boolean... 05-02-2019, 11:10 AM
Greg M Re: how to skip a boolean... 05-02-2019, 06:21 PM
dmcgov Re: how to skip a boolean... 05-03-2019, 06:57 AM
Greg M Re: how to skip a boolean... 05-03-2019, 07:40 AM
  1. #1
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    how to skip a boolean checkbox

    i have this workbook that cycle's through a sheet (actually two) and i want to mark a particular shortcut as read. this is working but when i press the next or previous button (to cycle), it stops and doesn't jump over a true checkbox. will upload the workbook for you to see.

    here is what i think needs to be configured:

    Private Sub CheckBox1_Click()
    
        indexVBA = ThisWorkbook.Sheets("Formulas").Range("IndexVBA")
        indexExcel = ThisWorkbook.Sheets("Formulas").Range("IndexExcel")
        'test for listbox being "VBA"
        If ListBox1.Value = "VBA" Then
            'test for checkbox being "True"
            If CheckBox1.Value = True Then
                chkbxV(indexVBA) = True
                If indexVBA < 99 Then
                    indexVBA = indexVBA + 1
                    If chkbxV(indexVBA) = True Then
                        indexVBA = indexVBA + 1
                    End If
                Else
                    indexVBA = indexVBA - 1
                End If
                Sheets("Formulas").Range("A2") = indexVBA
                ListBox1_Click
                CheckBox1.Value = False
            Else
                chkbxV(itemVBA) = False
            End If
            Debug.Print "chkbxV(" & itemVBA & ") is " & chkbxV(itemVBA)
            
        Else
            
            If ListBox1.Value = "Excel" Then
            'do excel here
            End If
    End Sub
    i think that this is just a mess and will probably have to be completely rewritten.

    also my next and previous seems to be working ok, but not sure if there needs to be coded added to it.
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,963

    Re: how to skip a boolean checkbox

            Debug.Print "chkbxV(" & itemVBA & ") is " & chkbxV(itemVBA)
            
        Else
            If ListBox1.Value = "Excel" Then
            'do excel here
            End If
        End If 
    End Sub
    Ben Van Johnson

  3. #3
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: how to skip a boolean checkbox

    i don't understand protonLeah, how does the end if fix my skip the read checkbox?

  4. #4
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,642

    Re: how to skip a boolean checkbox

    Hi there,

    Take a look at the attached version of your workbook and see if it does what you need.

    The big disadvantage of your original version is that (because values are stored in an array) the list of completed shortcuts is not "remembered" between sessions - i.e. every time the workbook is opened, the entire list of shortcuts is presented. The attached version stores values in a worksheet range so that they are "remembered" between sessions.

    Another change is that when scrolling forwards, the list of shortcuts scrolls from the last item in the list to the first item; likewise when scrolling backwards, the list scrolls from the first item to the last item. In either case, those shortcuts which have been marked as completed do not appear in the list of available shortcuts.

    There was quite a bit of rewriting to do, but it was an interesting project!


    The attached workbook uses the following code:

    
    
    
    Option Explicit
    
    
    '=========================================================================================
    '=========================================================================================
    
    
    Const miNO_OF_SHORTCUTS__EXCEL  As Integer = 76
    Const miNO_OF_SHORTCUTS__VBA    As Integer = 99
    
    Const msHEADER_EXCEL            As String = "ptrHeader_Excel"
    Const msHEADER_VBA              As String = "ptrHeader_VBA"
    Const msEXCEL                   As String = "Excel"
    Const msVBA                     As String = "VBA"
    
    
    '=========================================================================================
    '=========================================================================================
    
    
    Private mbEventsAreEnabled      As Boolean
    
    
    '=========================================================================================
    '=========================================================================================
    
    
    Private Sub UserForm_Initialize()
    
        With Me
    
    '       Note:  This value must be set BEFORE the ListIndex property is set below
            txtShortcutNo.Value = 0
    
            lstContext.AddItem msVBA
            lstContext.AddItem msEXCEL
            lstContext.ListIndex = 0
    
        End With
    
        mbEventsAreEnabled = True
    
    End Sub
    
    
    '=========================================================================================
    '=========================================================================================
    
    
    Private Sub lstContext_Click()
    
        Me.txtShortcutNo.Value = 0
    
        Call btnNext_Click
    
    End Sub
    
    
    '=========================================================================================
    '=========================================================================================
    
    
    Private Sub btnNext_Click()
        Call ChangeShortcutNo(iIncrement:=1)
    End Sub
    
    
    '=========================================================================================
    '=========================================================================================
    
    
    Private Sub btnPrevious_Click()
        Call ChangeShortcutNo(iIncrement:=-1)
    End Sub
    
    
    '=========================================================================================
    '=========================================================================================
    
    
    Private Sub chkCompleted_Click()
    
        Dim rLastCell   As Range
    
        If mbEventsAreEnabled = True Then
    
            If lstContext.Value = msVBA Then
                  Set rLastCell = wksCompleted.Range(msHEADER_VBA)
            Else: Set rLastCell = wksCompleted.Range(msHEADER_EXCEL)
            End If
    
            If rLastCell.Offset(1, 0).Value <> vbNullString Then
                Set rLastCell = rLastCell.End(xlDown)
            End If
    
            If Me.chkCompleted.Value = True Then
    
                  Set rLastCell = rLastCell.Offset(1, 0)
    
                  rLastCell.Value = Me.txtShortcutNo.Value
    
            Else: rLastCell.ClearContents
    
            End If
    
        End If
    
    End Sub
    
    
    '=========================================================================================
    '=========================================================================================
    
    
    Private Sub btnReset_Click()
    
        Dim iNoOfShortcuts  As Integer
        Dim iUserResponse   As Integer
        Dim rHeaderCell     As Range
        Dim sContext        As String
    
        sContext = Me.lstContext.Value
    
        If sContext = msEXCEL Then
    
              iNoOfShortcuts = miNO_OF_SHORTCUTS__EXCEL
              Set rHeaderCell = wksCompleted.Range(msHEADER_EXCEL)
    
        Else: iNoOfShortcuts = miNO_OF_SHORTCUTS__VBA
              Set rHeaderCell = wksCompleted.Range(msHEADER_VBA)
    
        End If
    
        iUserResponse = MsgBox("This will unselect all of the " & sContext & _
                               " Shortcuts marked as ""Completed""" & _
                                vbLf & vbLf & _
                               "Are you sure you wish to continue?", _
                                vbYesNo + vbDefaultButton2, " Confirm operation")
    
        If iUserResponse = vbYes Then
    
            With rHeaderCell.Offset(1, 0)
    
                Range(.Cells(1, 1), _
                      .Cells(iNoOfShortcuts)).ClearContents
    
            End With
    
            Me.txtShortcutNo.Value = 0
            Call btnNext_Click
    
        End If
    
    End Sub
    
    
    '=========================================================================================
    '=========================================================================================
    
    
    Private Sub ChangeShortcutNo(iIncrement As Integer)
    
        Dim iLastShortcutNo As Integer
        Dim rCompletedCells As Range
        Dim rCompletedCell  As Range
        Dim iShortcutNo     As Integer
        Dim rHeaderCell     As Range
    
        If Me.chkCompleted.Value = True Then
            mbEventsAreEnabled = False
                Me.chkCompleted.Value = False
            mbEventsAreEnabled = True
        End If
    
        With wksCompleted
    
            If lstContext.Value = msVBA Then
    
                  Set rHeaderCell = .Range(msHEADER_VBA)
                  iLastShortcutNo = miNO_OF_SHORTCUTS__VBA
    
            Else: Set rHeaderCell = .Range(msHEADER_EXCEL)
                  iLastShortcutNo = miNO_OF_SHORTCUTS__EXCEL
    
            End If
    
            With rHeaderCell
                Set rCompletedCells = Range(.Cells(2, 1), _
                                            .Cells(iLastShortcutNo + 1, 1))
            End With
    
            iShortcutNo = Me.txtShortcutNo.Value
    
            Do
    
                iShortcutNo = iShortcutNo + iIncrement
    
                If iShortcutNo > iLastShortcutNo Then
    
                          iShortcutNo = 1
    
                ElseIf iShortcutNo = 0 Then
    
                          iShortcutNo = iLastShortcutNo
    
                End If
    
                Set rCompletedCell = rCompletedCells.Cells.Find(What:=iShortcutNo, _
                                                                LookIn:=xlValues, _
                                                                LookAt:=xlWhole)
    
            Loop While Not rCompletedCell Is Nothing
    
            Me.txtShortcutNo.Value = iShortcutNo
    
            Call UpdateShortcutDetails
    
        End With
    
    End Sub
    
    
    '=========================================================================================
    '=========================================================================================
    
    
    Private Sub UpdateShortcutDetails()
    
        Const sCOLUMN_HELP  As String = "C"
        Const sCOLUMN_KEY   As String = "B"
        Const sCOLUMN_NO    As String = "A"
    
        Dim iShortcutNo As Integer
        Dim wks         As Worksheet
    
        If Me.lstContext.Value = msVBA Then
              Set wks = wksVBA
        Else: Set wks = wksExcel
        End If
    
        iShortcutNo = Me.txtShortcutNo.Value
    
        If iShortcutNo > 0 Then
    
            txtShortcutNo.Value = wks.Range(sCOLUMN_NO & iShortcutNo).Value
            txtShortcutKey.Value = wks.Range(sCOLUMN_KEY & iShortcutNo).Value
            txtShortcutHelp.Value = wks.Range(sCOLUMN_HELP & iShortcutNo).Value
    
        End If
    
    End Sub
    The highlighted values should be altered appropriately if shortcuts are added to or deleted from the lists.


    Hope this helps - please let me know how you get on.

    Regards,

    Greg M
    Attached Files Attached Files

  5. #5
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,642

    Re: how to skip a boolean checkbox

    Hi again,

    Here's a very slightly neater version of the "ChangeShortcutNo" routine:

    
    
    Private Sub ChangeShortcutNo(iIncrement As Integer)
    
        Dim iLastShortcutNo As Integer
        Dim rCompletedCells As Range
        Dim rCompletedCell  As Range
        Dim iShortcutNo     As Integer
        Dim rHeaderCell     As Range
    
        If Me.chkCompleted.Value = True Then
            mbEventsAreEnabled = False
                Me.chkCompleted.Value = False
            mbEventsAreEnabled = True
        End If
    
        With wksCompleted
    
            If lstContext.Value = msVBA Then
    
                  Set rHeaderCell = .Range(msHEADER_VBA)
                  iLastShortcutNo = miNO_OF_SHORTCUTS__VBA
    
            Else: Set rHeaderCell = .Range(msHEADER_EXCEL)
                  iLastShortcutNo = miNO_OF_SHORTCUTS__EXCEL
    
            End If
    
        End With
    
        With rHeaderCell
            Set rCompletedCells = Range(.Cells(2, 1), _
                                        .Cells(iLastShortcutNo + 1, 1))
        End With
    
        iShortcutNo = Me.txtShortcutNo.Value
    
        Do
    
            iShortcutNo = iShortcutNo + iIncrement
    
            If iShortcutNo > iLastShortcutNo Then
    
                      iShortcutNo = 1
    
            ElseIf iShortcutNo = 0 Then
    
                      iShortcutNo = iLastShortcutNo
    
            End If
    
            Set rCompletedCell = rCompletedCells.Cells.Find(What:=iShortcutNo, _
                                                            LookIn:=xlValues, _
                                                            LookAt:=xlWhole)
    
        Loop While Not rCompletedCell Is Nothing
    
        Me.txtShortcutNo.Value = iShortcutNo
    
        Call UpdateShortcutDetails
    
    End Sub

    Regards,

    Greg M
    Attached Files Attached Files

  6. #6
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: how to skip a boolean checkbox

    thanks Greg M for doing that. lots of new code to disseminate. works like a charm. 2 gold stars for you.

  7. #7
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,642

    Re: how to skip a boolean checkbox

    Hi again,

    Many thanks for your feedback, the Reputation increase, and of course the two gold stars - much appreciated!

    You're welcome - glad I was able to help.

    Best regards,

    Greg M

  8. #8
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: how to skip a boolean checkbox

    so i need to tweak your code a bit. added this code to ChangeShortcutNo:

        If lstContext = msVBA Then
            Sheets("Completed").Range("C2") = iShortcutNo
        Else
            Sheets("Completed").Range("D2") = iShortcutNo
        End If
    so it properly puts the shortcutNo in the completed sheet. now how can i reference this when the form is initialized. my reason for doing this is your code always starts at 1 for both VBA and Excel. but i need to "remember" where the user (me) left off. can you assist?

    here is where i added the code to:

    Private Sub ChangeShortcutNo(iIncrement As Integer)
    
        Dim iLastShortcutNo As Integer
        Dim rCompletedCells As Range
        Dim rCompletedCell  As Range
        Dim iShortcutNo     As Integer
        Dim rHeaderCell     As Range
    
        If Me.chkCompleted.Value = True Then
            mbEventsAreEnabled = False
                Me.chkCompleted.Value = False
            mbEventsAreEnabled = True
        End If
    
        With wksCompleted
    
            If lstContext.Value = msVBA Then
    
                  Set rHeaderCell = .Range(msHEADER_VBA)
                  iLastShortcutNo = miNO_OF_SHORTCUTS__VBA
    
            Else: Set rHeaderCell = .Range(msHEADER_EXCEL)
                  iLastShortcutNo = miNO_OF_SHORTCUTS__EXCEL
    
            End If
    
        End With
    
        With rHeaderCell
            Set rCompletedCells = Range(.Cells(2, 1), _
                                        .Cells(iLastShortcutNo + 1, 1))
        End With
    
        iShortcutNo = Me.txtShortcutNo.Value
        If lstContext = msVBA Then
            Sheets("Completed").Range("C2") = iShortcutNo
        Else
            Sheets("Completed").Range("D2") = iShortcutNo
        End If
        Do
    
            iShortcutNo = iShortcutNo + iIncrement
    
            If iShortcutNo > iLastShortcutNo Then
    
                      iShortcutNo = 1
    
            ElseIf iShortcutNo = 0 Then
    
                      iShortcutNo = iLastShortcutNo
    
            End If
    
            Set rCompletedCell = rCompletedCells.Cells.Find(What:=iShortcutNo, _
                                                            LookIn:=xlValues, _
                                                            LookAt:=xlWhole)
    
        Loop While Not rCompletedCell Is Nothing
    
        Me.txtShortcutNo.Value = iShortcutNo
        If lstContext = msVBA Then
            Sheets("Completed").Range("C2") = iShortcutNo
        Else
            Sheets("Completed").Range("D2") = iShortcutNo
        End If
        Call UpdateShortcutDetails
    
    End Sub
    Last edited by dmcgov; 05-02-2019 at 11:16 AM.

  9. #9
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,642

    Re: how to skip a boolean checkbox

    Hi again,

    Ok on needing to "remember" the positions of the currently-selected shortcuts.

    The attached workbook seems to do what you want - the main additions/changes to the original code are highlighted below:

    
    Const msCURRENT_EXCEL           As String = "ptrCurrent_Excel"
    Const msCURRENT_VBA             As String = "ptrCurrent_VBA"
    
    
    
    '=========================================================================================
    '=========================================================================================
    
    
    Private Sub lstContext_Click()
    
        Dim iShortcutNo As Integer
        Dim rShortcutNo As Range
    
        If Me.lstContext.Value = msEXCEL Then
              Set rShortcutNo = wksCompleted.Range(msCURRENT_EXCEL)
        Else: Set rShortcutNo = wksCompleted.Range(msCURRENT_VBA)
        End If
    
    '   Set the Shortcut No to one less than the currently-displayed value - it
    '   will be incremented by one when the btnNext_Click routine is executed
        iShortcutNo = rShortcutNo.Value - 1
    
        Me.txtShortcutNo.Value = iShortcutNo
    
        Call btnNext_Click
    
    End Sub
    
    
    '=========================================================================================
    '=========================================================================================
    
    
    Private Sub ChangeShortcutNo(iIncrement As Integer)
    
        Dim iLastShortcutNo As Integer
        Dim rCompletedCells As Range
        Dim rCompletedCell  As Range
        Dim rCurrentCell    As Range
        Dim iShortcutNo     As Integer
        Dim rHeaderCell     As Range
    
        If Me.chkCompleted.Value = True Then
            mbEventsAreEnabled = False
                Me.chkCompleted.Value = False
            mbEventsAreEnabled = True
        End If
    
        With wksCompleted
    
            If lstContext.Value = msVBA Then
    
                  Set rCurrentCell = .Range(msCURRENT_VBA)
                  Set rHeaderCell = .Range(msHEADER_VBA)
                  iLastShortcutNo = miNO_OF_SHORTCUTS__VBA
    
            Else: Set rCurrentCell = .Range(msCURRENT_EXCEL)
                  Set rHeaderCell = .Range(msHEADER_EXCEL)
                  iLastShortcutNo = miNO_OF_SHORTCUTS__EXCEL
    
            End If
    
        End With
    
        With rHeaderCell
            Set rCompletedCells = Range(.Cells(2, 1), _
                                        .Cells(iLastShortcutNo + 1, 1))
        End With
    
        iShortcutNo = Me.txtShortcutNo.Value
    
        Do
    
            iShortcutNo = iShortcutNo + iIncrement
    
            If iShortcutNo > iLastShortcutNo Then
    
                      iShortcutNo = 1
    
            ElseIf iShortcutNo = 0 Then
    
                      iShortcutNo = iLastShortcutNo
    
            End If
    
            Set rCompletedCell = rCompletedCells.Cells.Find(What:=iShortcutNo, _
                                                            LookIn:=xlValues, _
                                                            LookAt:=xlWhole)
    
        Loop While Not rCompletedCell Is Nothing
    
        Me.txtShortcutNo.Value = iShortcutNo
    
        rCurrentCell.Value = iShortcutNo
    
        Call UpdateShortcutDetails
    
    End Sub

    The "btnReset_Click" routine also contains some additional code to reset the values of the currently-selected Shortcuts to 1.


    Hope this helps - as before, please let me know how you get on.

    Regards,

    Greg M
    Attached Files Attached Files

  10. #10
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: how to skip a boolean checkbox

    thanks again Greg M, your a Winner! Hope others can get some use out of this as I know I will.

  11. #11
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,642

    Re: how to skip a boolean checkbox

    Hi again,

    You're very welcome - glad I was able to help.

    Best regards,

    Greg M

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. how to skip user form clear to skip particular text box
    By narsing18 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-05-2017, 08:44 AM
  2. [SOLVED] Exit Workbook_BeforeClose(Cancel As Boolean) if a public boolean = true
    By meabrams in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-20-2016, 06:10 AM
  3. Select All Checkboxes Checkbox That Also Calls Checkbox Macros
    By Intervigilium in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-23-2015, 06:41 PM
  4. # of blank labels to skip
    By jdlc in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-22-2014, 03:36 PM
  5. Protect the sheet but the form checkbox still can be change and sort by checkbox
    By carolyn1221 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-19-2014, 01:08 PM
  6. Formula for avg skip, max skip, longest out
    By Jordans121 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-12-2010, 04:56 PM
  7. Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) problem
    By 2funny4words in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-29-2009, 07:28 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1