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