How to remove the caption from string variable

Pookiemeister

Active Member
Joined
Jan 6, 2012
Messages
491
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
On my user-form, I have three checkboxes and public string variable called Description. For test purposes, I am using a message box to display the outcome. What I am wanting to do, if the user selects a checkbox it displays the caption of the checkbox in the message box. As another checkbox gets checked, it adds it to the variable. If the user deselects a checkbox, how can I remove it from the variable string? If there are any questions, comments, or concerns, please let me know. Thank you.

VBA Code:
Private Sub chkbxCIMN_Click()
   
    If chkbxCIMN.Value = True Then
        Description = Description & UCase(chkbxCIMN.Caption) & ", "
        MsgBox Description
    Else
        If Description = UCase(chkbxCIMN.Caption) Then
            Description = Description & ""
            MsgBox Description
        End If
       
    End If

End Sub
VBA Code:
Private Sub chkbxKP_Click()
    If chkbxKP.Value = True Then
        Description = Description & UCase(chkbxKP.Caption) & ", "
        MsgBox Description
    Else
        MsgBox Description
    End If
    
End Sub

VBA Code:
Private Sub chkbxTroubleshoot_Click()
    If chkbxTroubleshoot.Value = True Then
        Description = Description & UCase(chkbxTroubleshoot.Caption) & ", "
        MsgBox Description
    Else
        MsgBox Description
    End If
End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
62,265
Office Version
  1. 365
Platform
  1. Windows
How about
VBA Code:
Private Sub chkbxCIMN_Click()
   
    If chkbxCIMN.Value = True Then
        Description = Description & UCase(chkbxCIMN.Caption) & ", "
    Else
        Description = Replace(Description, chkbxCIMN.Caption & ", ", "", , , vbTextCompare)
    End If
    MsgBox Description

End Sub
 

Forum statistics

Threads
1,141,128
Messages
5,704,446
Members
421,350
Latest member
jake9951

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top