VBA Excel:填充电子表格的Userform仅更新同一行

时间:2017-10-26 16:28:48

标签: vba excel-vba excel

在Excel 2013中,我创建了一个用户表单来填充电子表格。

代码只更新电子表格的第二行,而不是在点击&#34时跳转到下一行;确定",它会不断更新同一行。

我需要它来更新第一行(A6)并继续下一个空行。

" OK"的当前代码按钮:

Private Sub cmdOK_Click()

    Dim RowCount As Long
    Dim ctl As Control

    RowCount = Worksheets("Serviços-Componentes").Range("A4").CurrentRegion.Rows.Count

    With Worksheets("Serviços-Componentes").Range("A4")

        .Offset(RowCount, 0).value = Me.txtServ.value
        .Offset(RowCount, 1).value = Me.cmbFluxos.value & "." & Me.cmbSubFluxos

        If Me.checkMQ.value = True Then
            .Offset(RowCount, 2).value = "X"
        Else
            .Offset(RowCount, 2).value = ""
        End If

        If Me.checkHTTP.value = True Then
            .Offset(RowCount, 3).value = "X"
        Else
            .Offset(RowCount, 3).value = ""
        End If

        If Me.checkLU62.value = True Then
            .Offset(RowCount, 4).value = "X"
        Else
            .Offset(RowCount, 4).value = ""
        End If

        If Me.checkDpower.value = True Then
            .Offset(RowCount, 5).value = "X"
        Else
            .Offset(RowCount, 5).value = ""
        End If

        If Me.checkIIB.value = True Then
            .Offset(RowCount, 6).value = "X"
        Else
            .Offset(RowCount, 6).value = ""
        End If

        If Me.checkWAS.value = True Then
            .Offset(RowCount, 7).value = "X"
        Else
            .Offset(RowCount, 7).value = ""
        End If

        If Me.checkMFM.value = True Then
            .Offset(RowCount, 8).value = "X"
        Else
            .Offset(RowCount, 8).value = ""
        End If

        .Offset(RowCount, 9).value = Me.txtReq.value
        .Offset(RowCount, 10).value = Me.txtResp.value
    End With

    ' Clear the form
     For Each ctl In Me.Controls
        If TypeName(ctl) = "TextBox" Or TypeName(ctl) = "ComboBox" Then
            ctl.value = ""
        ElseIf TypeName(ctl) = "CheckBox" Then
            ctl.value = False
        End If
     Next ctl
End Sub

0 个答案:

没有答案