[英]Excel Dynamic Dropdown go to Cell
Private Sub Worksheet_Change(ByVal Target As Range)
Select Case Range("B1").Value
Case Is = "G&A Total"
Application.Goto Range("G_A_Total"), Scroll:=True
Case Is = "Accounting"
Application.Goto Range("Accounting"), Scroll:=True
Case Is = "Environmental"
Application.Goto Range("Environmental"), Scroll:=True
Case Is = "GSC"
Application.Goto Range("GSC"), Scroll:=True
Case Is = "Human Resources"
Application.Goto Range("Human_Resources"), Scroll:=True
End Select
End Sub
I currently have this code which works with a data verification drop down. 我目前有此代码,可用于数据验证下拉列表。 What I want to know is there anyway to make this dynamic so that anything I put in the list becomes what it is pulling from instead of having to manually enter each one.
无论如何,我想知道有什么要使它动态化的,因此我放入列表中的任何内容都将成为它从中提取的内容,而不必手动输入每个内容。
Current Edits below. 下面的当前编辑。
Private Sub Worksheet_Change(ByVal Target As Range)
Select Case Range("B1").Value
Case Is = Range("A1")
Application.Goto Range("G_A_Total"), Scroll:=True
Case Is = Range("A2")
Application.Goto Range("Accounting"), Scroll:=True
Case Is = Range("A3")
Application.Goto Range("Environmental"), Scroll:=True
Case Is = Range("A4")
Application.Goto Range("GSC"), Scroll:=True
Case Is = Range("A5")
Application.Goto Range("Human_Resources"), Scroll:=True
End Select
End Sub
I changed out the specific Case Is to be cell references which reference the cells selected by Data Validation instead of refering to each individual cell is there a way to range name them then refer to the range name? 我更改了特定的案例,是要成为引用数据验证所选单元的单元格引用,而不是引用每个单独的单元格,有没有办法对它们进行范围命名,然后再引用范围名称?
Maybe something such as this 也许像这样
Select Case Range("B1").Value
Case Is = Range("Departments")
Application.Goto Range("DepartmentsGoTo"), Scroll:=True
End Select
Then have 2 ranged named column that I can update to avoid having to change the code often? 然后,我可以更新2个有范围的命名列,以避免经常更改代码?
Basically, compare each Named range with the value in B1
基本上,将每个命名范围与
B1
的值进行比较
Private Sub Worksheet_Change(ByVal Target As Range)
For Each myName In ActiveWorkbook.Names
Select Case Range("B1").Value
Case myName.Name
Application.Goto Reference:=myName.Name, Scroll:=True
End Select
Next
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.