2013-07-02 39 views
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 

如何連接這兩段代碼?

回答

1

合併第二碼與第一,與Cells(NextRow, 3)第一線替換Selection

你需要分割你的整個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.. 
+0

哈 - 很簡單!謝謝,就是我想要的。 – halcyon27

相關問題