Results 1 to 4 of 4

Set Userform Checkbox value to True if CheckBox.Caption string is found in another String

Threaded View

TFiske Set Userform Checkbox value... 03-28-2018, 03:10 PM
TFiske Re: Set Userform Checkbox... 03-28-2018, 03:29 PM
Arkadi Re: Set Userform Checkbox... 03-28-2018, 03:31 PM
TFiske Re: Set Userform Checkbox... 03-28-2018, 03:39 PM
  1. #1
    Forum Contributor
    Join Date
    03-30-2016
    Location
    Gillette, WY
    MS-Off Ver
    Office 365
    Posts
    230

    Set Userform Checkbox value to True if CheckBox.Caption string is found in another String

    Hi all, TFiske...again,

    First of all, I want to thank to AlphaFrog, mehmetcik, Arkadi, bakerman2, xladept, and Winon for their help in getting me this far with this project.

    Here's the new problem:

    I have a Multi-Tab UserForm in which the user will check boxes if a given chemical is of a given type. Then the .Caption parameter for each box checked is concatenated with the following code and stored in a cell in column 4 of the "Chemical's" table:

        Dim chkChem As Control
        Dim ChemType As String
        Dim delim As String
        
            delim = ", "
            For Each chkChem In Me.Frm_ChemType.Controls
                If TypeOf chkChem Is MSForms.CheckBox Then
                    If (chkChem.Value = True) Then
                        ChemType = ChemType & delim & chkChem.Caption
                    End If
                End If
            Next
    Now, on the Edit Chemical Record tab of the userform, I need to set these checkboxes to True if their caption is found in the string generated by the code above when the user selects a stored Chemical Record from a ComboBox. I've tried a few approaches but haven't gotten anywhere.
    Most recently I've tried a public function with InStr:

    Private Sub ctrl1_Change()
    
        Dim wb As Workbook
        Dim ws As Worksheet
        
            Set wb = ThisWorkbook
            Set ws = wb.Worksheets("Chemicals")
    
        Dim rowIndex As Long
        Dim c As Long
    
        rowIndex = Application.Match(Me.ctrl1.Value, ws.Columns(1), 0)
        For c = 1 To 6
            Public Function ChemCheck(ChemBaseStr As String, ChemTypeStr As String) As Boolean
                ChemBaseStr = ws.Cells(rowIndex, 4)
                ChemTypeStr = Me.Controls("chk" & c).Caption
                ChemCheck = InStr(ChemBaseStr, ChemTypeStr)
                If ChemCheck = True Then
                    Me.Controls("chk" & c).Value = True
                End If
            End Function
        Next
    This latest method gives me an "Expected End Sub" error. The other method's I've tried don't seem to do anything. I've attached a copy of the project. The UserForm in question is UsrFrm_ChemicalMaintenance. Thanks again!
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Userform Checkbox Caption Font Size
    By didless in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-05-2017, 06:09 PM
  2. [SOLVED] Userform checkbox caption to hide work sheet
    By L plates in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-03-2017, 08:08 AM
  3. [SOLVED] Userform Checkbox caption
    By TimlmiT in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-03-2014, 10:28 AM
  4. [SOLVED] Change Checkbox Caption After Userform Activation
    By pjcbm9 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-29-2014, 08:15 PM
  5. [SOLVED] Userform to rename caption of Multipage as per Checkbox
    By calvinle in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-07-2014, 11:07 AM
  6. Change Checkbox Caption on Userform with Name in Variable
    By XLVBA in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-11-2013, 04:43 PM
  7. Get UserForm checkbox caption and pass to another UserForm on click or mouse down
    By tulsaguy71 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-08-2013, 11:07 AM

Tags for this Thread

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