ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   help in checkbox code (https://www.excelbanter.com/excel-programming/328076-help-checkbox-code.html)

Soniya[_4_]

help in checkbox code
 
Hi All,

I have the following code.

Private Sub CommandButton1_Click()
MyStr = ""
For Each ctl In BranchSelect.Controls

If TypeOf ctl Is MSForms.CheckBox Then
If ctl.Value = True Then
MyStr = MyStr & Left(ctl.Caption, 3) & ","
End If
End If
Next
MyStr = "{" & MyStr & "0}"
LblOffc.Caption = MyStr
End Sub


the first three charecters of my checkbox captions are like
100,101,102,103,104 etc

what i am looking for is to get LblOffc.Caption like {101,102,104} if i
have checked checkboxes with 101,102,103 as their caption (first 3
digits)

in my above code i have an extra 0 and an extra coma (,) which i want
to remove. also in case all items de selected caption shud be empty
("") now i am having {0} there..

any help..

thanks


Toppers

help in checkbox code
 
Hi,
Your code adds the 0 in:

MyStr = "{" & MyStr & "0}"

Add the following after the NEXT statement:

If MyStr< "" then
myStr=left(MyStr,len(MyStr)-1) ' removes last comma (,)'
MyStr = "{" & MyStr & "}"
End if
LblOffc.Caption = MyStr


HTH
"Soniya" wrote:

Hi All,

I have the following code.

Private Sub CommandButton1_Click()
MyStr = ""
For Each ctl In BranchSelect.Controls

If TypeOf ctl Is MSForms.CheckBox Then
If ctl.Value = True Then
MyStr = MyStr & Left(ctl.Caption, 3) & ","
End If
End If
Next
MyStr = "{" & MyStr & "0}"
LblOffc.Caption = MyStr
End Sub


the first three charecters of my checkbox captions are like
100,101,102,103,104 etc

what i am looking for is to get LblOffc.Caption like {101,102,104} if i
have checked checkboxes with 101,102,103 as their caption (first 3
digits)

in my above code i have an extra 0 and an extra coma (,) which i want
to remove. also in case all items de selected caption shud be empty
("") now i am having {0} there..

any help..

thanks




All times are GMT +1. The time now is 12:08 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com