-1
使用數據驗證輸入消息,對於命名範圍(「MyRange」)中的每個單元格,我希望匹配Table1 [Column1]和索引值表1 [列2]。Excel VBA:索引匹配的動態數據驗證輸入消息
我需要循環,因爲它不會,活動單元保持不變,整個範圍都有相同的輸入消息。我沒有承諾公式INDEX MATCH,它只需要執行該功能。
Sub Tester()
Dim mycell As String
mycell = ActiveCell
With Range("MyRange").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertInformation, _
Operator:=xlBetween, Formula1:="=INDIRECT(Test1&Test2)"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = Application.WorksheetFunction.Index(Range("Table1[Column2]"), _
Application.WorksheetFunction.Match(mycell, Range("Table1[Column1]"), 0))
.ErrorMessage = ""
.ShowInput = True
.ShowError = False
End With
End Sub
謝謝你的幫助!
有沒有循環?您只需要進行範圍驗證...您希望它在哪裏循環? *至少*你會想在你第一次使用'Cells(activecell.row + 1,ActiveCell.Column)'後改變activecell。 ...但也不要這樣做,因爲它[最好避免使用'.Select' /'.Activate'](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select -in-Excel的VBA)。 – BruceWayne
我不指望它。這是我想解決的問題。 :) – AlivePresumably
你可以做一個網絡搜索有關在一個範圍內循環.... http://www.excel-easy.com/vba/examples/loop-through-defined-range.html – jsotola