Excel 2010:如何在validation列表中使用自动完成function
我正在使用一个大的validation列表,几个vlookup()函数依赖。 这份名单越来越大。 有没有办法input我正在寻找的列表项的第一个字母,而不是手动向下滚动search项目列表?
我做了一些谷歌search,但这表明,这确实可能在早期版本的Excel中,但不是在Excel 2010中。希望你们可以帮忙。
谢谢。
这是处理这个问题的一个很好的方法(在ozgrid上find ):
在Sheet1
A1
input=Sheet2!A1
并根据需要复制包括尽可能多的备用行(总共说300行)。 隐藏这些行并在“引用到:”中使用此公式:对于名为MyList的dynamic命名范围:
=OFFSET(Sheet1!$A$1,0,0,MATCH("*",Sheet1!$A$1:$A$300,-1),1)
现在在最后一个隐藏行下面的单元格中使用数据validation,并使用列表来源use =MyList
[编辑] Excel 2007+的适应版本(不能在2010年testing,但AFAIK,没有真正特定的版本)。
假设您的数据源位于Sheet2!A1:A300
,假设您的validation列表(又名自动完成 )位于单元Sheet1!A1
。
-
创build一个dynamic的命名范围
MyList
,它将取决于您放置validation的单元格的值= OFFSET(1 Sheet2的$ A $,MATCH(Sheet 1中$ A $ 1 “*”; Sheet2的$ A $ 1:!!$ A $ 300; 0)-1; 0; COUNTA(Sheet 2中$ A:$ A))
-
在单元格
Sheet1!A1
上添加validation列表,将返回到list=MyList
MyList
注意事项
-
这不是真正的自动完成,因为您必须先键入,然后单击validation箭头:列表将从列表的第一个匹配元素开始
-
该列表将一直持续到您的数据结束。 如果你想要更精确的话(只保留匹配元素的列表),你可以用一个
SUMLPRODUCT
来改变COUNTA
,这个SUMLPRODUCT
将计算匹配元素的数量 -
您的来源列表必须sorting
只要有垂直的项目列,Excel自动执行此操作。 如果您select列下方(或上方)的空白单元格并开始input,则会根据列中的所有内容自动填充。
build立在JMax的答案上,使用该公式作为dynamic命名范围,使解决scheme适用于多行:
= OFFSET(Sheet2中$ A $ 1,MATCH(INDIRECT( “工作表Sheet1!” &ADDRESS(ROW(),COLUMN(),4)) “*”,Sheet2的$ A $ 1:!$ A $ 300,0)-1, 0,COUNTA(Sheet2的$ A:$ A))
=OFFSET(NameList!$A$2:$A$200,MATCH(INDIRECT("FillData!"&ADDRESS(ROW(),COLUMN(),4))&"*",NameList!$A$2:$A$200,0)-1,0,COUNTIF($A$2:$A$200,INDIRECT("FillData!"&ADDRESS(ROW(),COLUMN(),4))&"*"),1)
1.将表格名称作为列表A中的名称填入数据列表。
2.根据需要将表名称作为FillData来制作数据validation列表。
3.键入第一个字母并select,下拉菜单将依赖于你的types出现。
安南Phungmit
泰国
这是另一种select。 它通过在启用了validation的单元格顶部放置一个ActiveXcombobox,然后在ComboBox中提供自动完成function。
Option Explicit ' Autocomplete - replacing validation lists with ActiveX ComboBox ' ' Usage: ' 1. Copy this code into a module named m_autocomplete ' 2. Go to Tools / References and make sure "Microsoft Forms 2.0 Object Library" is checked ' 3. Copy and paste the following code to the worksheet where you want autocomplete ' ------------------------------------------------------------------------------------------------------ ' - autocomplete ' Private Sub Worksheet_SelectionChange(ByVal Target As Range) ' m_autocomplete.SelectionChangeHandler Target ' End Sub ' Private Sub AutoComplete_Combo_KeyDown(ByVal KeyCode As msforms.ReturnInteger, ByVal Shift As Integer) ' m_autocomplete.KeyDownHandler KeyCode, Shift ' End Sub ' Private Sub AutoComplete_Combo_Click() ' m_autocomplete.AutoComplete_Combo_Click ' End Sub ' ------------------------------------------------------------------------------------------------------ ' When the combobox is clicked, it should dropdown (expand) Public Sub AutoComplete_Combo_Click() Dim ws As Worksheet: Set ws = ActiveSheet Dim cbo As OLEObject: Set cbo = GetComboBoxObject(ws) Dim cb As ComboBox: Set cb = cbo.Object If cbo.Visible Then cb.DropDown End Sub ' Make it easier to navigate between cells Public Sub KeyDownHandler(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) Const UP As Integer = -1 Const DOWN As Integer = 1 Const K_TAB_______ As Integer = 9 Const K_ENTER_____ As Integer = 13 Const K_ARROW_UP__ As Integer = 38 Const K_ARROW_DOWN As Integer = 40 Dim direction As Integer: direction = 0 If Shift = 0 And KeyCode = K_TAB_______ Then direction = DOWN If Shift = 0 And KeyCode = K_ENTER_____ Then direction = DOWN If Shift = 1 And KeyCode = K_TAB_______ Then direction = UP If Shift = 1 And KeyCode = K_ENTER_____ Then direction = UP If Shift = 1 And KeyCode = K_ARROW_UP__ Then direction = UP If Shift = 1 And KeyCode = K_ARROW_DOWN Then direction = DOWN If direction <> 0 Then ActiveCell.Offset(direction, 0).Activate AutoComplete_Combo_Click End Sub Public Sub SelectionChangeHandler(ByVal Target As Range) On Error GoTo errHandler Dim ws As Worksheet: Set ws = ActiveSheet Dim cbo As OLEObject: Set cbo = GetComboBoxObject(ws) Dim cb As ComboBox: Set cb = cbo.Object ' Try to hide the ComboBox. This might be buggy... If cbo.Visible Then cbo.Left = 10 cbo.Top = 10 cbo.ListFillRange = "" cbo.LinkedCell = "" cbo.Visible = False Application.ScreenUpdating = True ActiveSheet.Calculate ActiveWindow.SmallScroll Application.WindowState = Application.WindowState DoEvents End If If Not HasValidationList(Target) Then GoTo ex Application.EnableEvents = False ' TODO: the code below is a little fragile Dim lfr As String lfr = Mid(Target.Validation.Formula1, 2) lfr = Replace(lfr, "INDIREKTE", "") ' norwegian lfr = Replace(lfr, "INDIRECT", "") ' english lfr = Replace(lfr, """", "") lfr = Application.Range(lfr).Address(External:=True) cbo.ListFillRange = lfr cbo.Visible = True cbo.Left = Target.Left cbo.Top = Target.Top cbo.Height = Target.Height + 5 cbo.Width = Target.Width + 15 cbo.LinkedCell = Target.Address(External:=True) cbo.Activate cb.SelStart = 0 cb.SelLength = cb.TextLength cb.DropDown GoTo ex errHandler: Debug.Print "Error" Debug.Print Err.Number Debug.Print Err.Description ex: Application.EnableEvents = True End Sub ' Does the cell have a validation list? Function HasValidationList(Cell As Range) As Boolean HasValidationList = False On Error GoTo ex If Cell.Validation.Type = xlValidateList Then HasValidationList = True ex: End Function ' Retrieve or create the ComboBox Function GetComboBoxObject(ws As Worksheet) As OLEObject Dim cbo As OLEObject On Error Resume Next Set cbo = ws.OLEObjects("AutoComplete_Combo") On Error GoTo 0 If cbo Is Nothing Then 'Dim EnableSelection As Integer: EnableSelection = ws.EnableSelection Dim ProtectContents As Boolean: ProtectContents = ws.ProtectContents Debug.Print "Lager AutoComplete_Combo" If ProtectContents Then ws.Unprotect Set cbo = ws.OLEObjects.Add(ClassType:="Forms.ComboBox.1", Link:=False, DisplayAsIcon:=False, _ Left:=50, Top:=18.75, Width:=129, Height:=18.75) cbo.name = "AutoComplete_Combo" cbo.Object.MatchRequired = True cbo.Object.ListRows = 12 If ProtectContents Then ws.Protect End If Set GetComboBoxObject = cbo End Function
正如其他人所build议的,您需要使用combobox。 但是,大多数教程都告诉你如何设置一个combobox,这个过程非常繁琐。
正如我在从列表中input大量数据之前遇到过这个问题,我build议您使用这个自动完成加载项 。 它可以帮助你在你select的任何单元格上创buildcombobox,你可以定义一个列表出现在下拉列表中。