在EXCEL中一个追加按钮,点击此按钮后弹出一个FORM ,在FORM中选择我所要追加的内容。现在我要向各位请教的是FORM中有多个复选框,假如有三条记录要追加到表中,别的内容都 一样就是复选框中所对应的 内容不一样,现在我想同时选择三个复选框所对应的内容,确定后把我所要追加的内容按序输出~~~
   问题就 是这样的~~谢谢各位帮帮忙~附件中也有 问题的描述~在线等待中~  附件传不上去,

解决方案 »

  1.   

    在Excel VBA中不能用控件数组,所以只能一个一个写Private Sub CommandButton1_Click()
        If CheckBox1 Then MySave (CheckBox1.Caption)
        If CheckBox2 Then MySave (CheckBox2.Caption)
        If CheckBox3 Then MySave (CheckBox3.Caption)
    End Sub
    Private Sub MySave(strYW As String)
        Dim l As Long
        l = [A65530].End(xlUp).Row + 1
        Range("A" & l) = Range("A" & l - 1) + 1
        Range("B" & l) = IIf(OptionButton1, OptionButton1.Caption, OptionButton2.Caption)
        Range("C" & l) = strYW
        Range("D" & l) = TextBox1
    End Sub
      

  2.   

      Hi!大家好!我是这个社区的新手,请多多关照……
      楼主的问题可以这样解决:Private Sub CommandButton1_Click()    Dim lLine&, sCompName$, sDate$
        
        lLine = 0
        If (OptionButton1 = True) Then
            sCompName = "A社"
            lLine = 1
        End If
        If (OptionButton2 = True) Then
            sCompName = "B社"
            lLine = 2
        End If
        If (lLine = 0) Then
            MsgBox "请选择公司名称!", 48, "错误!"
            Exit Sub
        End If
        sDate = TextBox1
        If (Len(sDate) = 0) Then
            MsgBox "请输入日期!", 48, "错误!"
            Exit Sub
        End If
        lLine = 4      '从第4行开始找空行
        Do
            If (Range("B" & lLine).Formula = "") Then Exit Do
            lLine = lLine + 1
        Loop
        If (CheckBox1 = True) Then
            Range("A" & lLine).Formula = lLine - 3
            Range("B" & lLine).Formula = sCompName
            Range("C" & lLine).Formula = "AS400开发"
            Range("D" & lLine).Formula = sDate
            lLine = lLine + 1
        End If
        If (CheckBox2 = True) Then
            Range("A" & lLine).Formula = lLine - 3
            Range("B" & lLine).Formula = sCompName
            Range("C" & lLine).Formula = "JAVA开发"
            Range("D" & lLine).Formula = sDate
            lLine = lLine + 1
        End If
        If (CheckBox3 = True) Then
            Range("A" & lLine).Formula = lLine - 3
            Range("B" & lLine).Formula = sCompName
            Range("C" & lLine).Formula = "combol开发"
            Range("D" & lLine).Formula = sDate
        End If
        Unload MeEnd Sub
      

  3.   

      楼主的FORM设计有一个小问题:既然公司用了选项按钮,那FORM载入后,就应该一个选项是默认选定的。
      这个可以在窗体的设计时完成,或在“追加”按钮的Click事件中用代码完成。Private Sub CommandButton1_Click()
    ' “追加”按钮的Click事件代码    Load UserForm1
        UserForm1.OptionButton1 = True   '假定“A社”为默认选定
        UserForm1.ShowEnd Sub
      这样对“公司名”的判断代码:
        lLine = 0 
        If (OptionButton1 = True) Then 
            sCompName = "A社" 
            lLine = 1 
        End If 
        If (OptionButton2 = True) Then 
            sCompName = "B社" 
            lLine = 2 
        End If 
        If (lLine = 0) Then 
            MsgBox "请选择公司名称!", 48, "错误!" 
            Exit Sub 
        End If   这一段就可简化为:
        If (OptionButton1 = True) Then 
            sCompName = "A社" 
        Else 
            sCompName = "B社" 
        End If     请大家多多指教!
      

  4.   

    楼上的也是新手吧,哈哈。
        If (OptionButton1 = True) Then  
            sCompName = "A社"  
        Else  
            sCompName = "B社"  
        End If  
    这一段就可简化为一句:
    sCompName=Iif(OptionButton1,"A","B") & "社"