VBA Loop

raccoon588

Board Regular
Joined
Aug 5, 2016
Messages
118
i have the following code, it loops through the check boxes within the user form. Id like to be able to have the message change depending on which check box is true. how could i adjust this loop to have a specific message per check box that is true and then keep going continuing the loop every time hitting a different true check box and giving a different message depending on what comes up true.



Code:
Private Sub CmdSubmit_Click()
Dim C As MSForms.Control
    For Each C In Me.Controls '<--| loop through userform controls
        If TypeName(C) = "CheckBox" Then
        If C.Value = True Then
        
            MsgBox C.Name 
            End If
        End If
        
    Next C


End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Try
Code:
               Case "FD"
                  msg = "Full Day," & Choose(CLng(Right(C.name, 1)), lblDayOne, lbldaytwo, lbldaythree)
                  MsgBox msg
                  Range("B" & Rows.count).End(xlUp).Offset(1).Resize(, 2).Value = Split(msg, ",")
 
Upvote 0
this works just as expected but is there a way to get the value of the label vs breaking up the message and dumping the text?
 
Upvote 0
my lables contain dates. when breaking up the message and dumping it into the excel sheet i get a string rather then a date.
 
Upvote 0
That's because labels contain strings, not dates ;)
 
Upvote 0
Try
Code:
                  Range("B" & Rows.count).End(xlUp).Offset(1).Value = Split(msg, ",")(0)
                  Range("C" & Rows.count).End(xlUp).Offset(1).Value = CDate(Split(msg, ",")(1))
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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
Back
Top