且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Excel VBA-将多个用户窗体复选框值写入单个单元格

更新时间:2023-11-30 16:00:52

将框架控件重命名为 frameColours ,然后可以循环其复选框&构建您的字符串;

Rename the frame control to frameColours then you can loop its checkboxes & build your string;

Dim chk as Control
Dim colors as string, delimiter as string

for Each chk In Me.frameColours.Controls
    if typeOf chk Is msforms.CheckBox then
        if (chk.Value) then
            colors = colors & delimiter & chk.Caption
            delimiter = ","
        end if
    end if
next

With colorsSheet
    .Cells(ActiveCell.Row, 1).Value = colors
End With