1

我有一个带有语言 ID 复选框的用户表单。选中后,将填充工作表“输出”上的一个单元格。这是代码:

Private Sub btnSubmit_Click()

Sheets("output").Activate

NextRow = Application.WorksheetFunction.CountA(Range("A:A")) + 1
    If cbxEnUs Then Cells(NextRow, 3) = "3 - en-us"
    If cbxFr Then Cells(NextRow, 4) = "3 - fr"
    If cbxIt Then Cells(NextRow, 5) = "3 - it"

Sheets("input").Activate

我想将以下数据验证(来自记录的宏)应用于接收值的每个单元格。

With Selection.Validation
    .Delete
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertInformation, _
    Operator:=xlBetween, Formula1:="3 - en-us,2 - en-us,1 - en-us"
    .IgnoreBlank = True
    .InCellDropdown = True
    .InputTitle = ""
    .ErrorTitle = "Incorrect value"
    .InputMessage = "3 = action req'd" & Chr(10) & "2 = in progress" & Chr(10) & "1 = complete"
    .ErrorMessage = "Please review valid input values" & Chr(10) & "and try again"
    .ShowInput = True
    .ShowError = True
End With

如何连接这两段代码?

4

1 回答 1

1

将第二个代码与第一个代码合并,将Selection第一行替换为Cells(NextRow, 3)等。

您需要跨行拆分 IF 语句:

If cbxEnUs Then 
    Cells(NextRow, 3) = "3 - en-us"
    ' apply validation to this cell
    With Cells(NextRow, 3).Validation
        'etc..
    End With
End if    'etc..
于 2013-07-02T17:01:21.163 回答