2
问题
我有两个下拉列表,是有办法来自动选择第二个下拉列表中,当我选择从第一个下拉列表中的选项?执行宏第二下拉列表中,当点击第一个下拉列表
下拉列表使用2数据透视表进行数据验证。
代码Private Sub Worksheet_Change(ByVal Target As Range)
Dim cell As Range
For Each cell In Target
If Not Intersect(cell, Range("F9")) Is Nothing Then
Call Sample_Click
ElseIf Not Intersect(cell, Range("F10")) Is Nothing Then
Call Sample2_Click
End If
Next cell
End Sub
Sample_Click
Dim ACount As Integer
Dim Dept As String
Dim Func As String
Dim Pos As String
Range("F9").Select
Dept = Trim(ActiveCell.Value)
Sheets("Sheet1").Select
ActiveSheet.PivotTables("PivotTable1").PivotFields("Dept").ClearAllFilters
ActiveSheet.PivotTables("PivotTable1").PivotFields("Dept").CurrentPage = Dept
ACount = ActiveSheet.PivotTables("PivotTable1").RowRange.Cells.Count
ACount = ACount + 2
Sheets("Home").Select
Range("F10").Select
With Selection.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=Sheet1!$A$4:$A$" & ACount
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
ActiveCell.Formula = ""
问题
Sample2_Click
相同Sample_Click
,唯一的区别是Range("")
值。 尽管我尝试了所有的努力,但我仍然收到错误信息。
你得到的错误是什么,以及哪行代码给出错误? – DragonSamu