没有select大小写错误下拉代码的情况

我继续在没有select大小写错误的情况下获取大小写,同时尝试应用代码使单元重置/更改的所有下拉选项在左侧选项更改时select。

我很新的VBA和macros的一面,如上所述,我想这个代码应用到整个工作表,我想这样做,当select下拉选项,如果回去,改变未来元素的一个元素(右边的所有东西)变回“select”选项。

我发现了一些在线代码,并试图改变它,以适应我的需求,但是每当我尝试运行它,我得到的情况下,没有大小写错误。 我使用的代码示例如下:

Option Explicit Const CHOOSE = "Choose" Private Sub Worksheet_Change(ByVal Target As Range) On Error GoTo ErrorHandler Dim targetCell As Range Dim nextCell As Range Dim oldCalc As Excel.XlCalculation If Not Intersect(Target, [DataEntryTable]) Is Nothing Then If [Radio_Choice] = 1 Then With Application .EnableEvents = False .ScreenUpdating = False oldCalc = .Calculation .Calculation = xlCalculationManual End With For Each targetCell In Target 'Clear any cells that use 'SubList' to the right of targetCell in the current table. If targetCell.Column < (targetCell.ListObject.ListColumns.Count + targetCell.ListObject.Range.Column - 1) Then 'there are table cells to the right For Each nextCell In targetCell.Offset(, 1).Resize(, targetCell.ListObject.ListColumns.Count + targetCell.ListObject.Range.Column - targetCell.Column - 1) If HasValidationFormula(nextCell) Then If nextCell.Validation.Formula1 = "=SubList" Then nextCell.Value = "" End If Next nextCell End If Select Case Target.Cells.Validation.Formula1 Case "=SubList" If targetCell.Value = "" Then targetCell.Value = CHOOSE ElseIf targetCell.Offset(, -1).Value = CHOOSE Then targetCell.Value = "" ElseIf targetCell.Value = CHOOSE Then 'Do nothing Else Set nextCell = targetCell.Offset(, 1) If HasValidationFormula(nextCell) Then If nextCell.Validation.Formula1 = "=SubList" Then nextCell.Value = CHOOSE End If End If End Select End If Next targetCell With Application .EnableEvents = True .ScreenUpdating = True .Calculation = oldCalc End With End If End If Exit Sub ErrorHandler: With Application .EnableEvents = True .ScreenUpdating = True If oldCalc <> 0 Then .Calculation = oldCalc End With MsgBox Err.Description, vbCritical, Name & ".Worksheet_Change()" End Sub Private Function HasValidationFormula(cell As Range) As Boolean On Error GoTo ValidationNotExistsError If cell.Validation.Formula1 <> "" Then HasValidationFormula = True Else HasValidationFormula = False End If Exit Function ValidationNotExistsError: HasValidationFormula = False End Function 

任何帮助将是伟大的。 这是我添加select案例时遇到的代码片断。

 Select Case Target.Cells.Validation.Formula1 Case "=SubList" If targetCell.Value = "" Then targetCell.Value = Choose ElseIf targetCell.Offset(, -1).Value = Choose Then targetCell.Value = "" ElseIf targetCell.Value = Choose Then 'Do nothing Else Set nextCell = targetCell.Offset(, 1) If HasValidationFormula(nextCell) Then If nextCell.Validation.Formula1 = "=SubList" Then nextCell.Value = Choose End If End If End Select 

Select语句的语法是:

 Select Case (expression) Case <case element> Case ... .... Case Else End Select 

在你的情况下,在你的第一个Case "=SubList"之前没有Select Case (expression)

我发现你的代码的问题,请看下面:

 '~~~~~~~~~~~~ above code ~~~~~~~~ If HasValidationFormula(nextCell) Then If nextCell.Validation.Formula1 = "=SubList" Then nextCell.Value = CHOOSE End If End If End Select End If '<- this line is extra '~~~~~~~~~~~~ below code ~~~~~~~~ 

只要删除额外的End If ,它会好的。