我需要帮助写一个Excel VBA Splat函数

我正在使用Excel 2007,需要一些帮助/指导如何编写一个Splat用户定义的函数function。 使用Splat函数可以将数据input到包含vlookup函数的单元格中,然后使用input的值更新查找表,但是vlookup公式将保留在单元格中。 我在下面提供了一个例子:

第1步 。 你有一个lookuptable和一组使用vlookup函数来显示表格数据的单元格。

在这里输入图像说明

第2步 。 在单元格d3中,用户input: / 500 。 /触发Splat函数,用Jane(500)的新值更新查找表,并replace单元格d3中的查找公式。

在这里输入图像说明

第3步 。 在Splat函数触发后,Jane在表中有500个值,单元格d3(通过查找函数)显示更新后的值。

在这里输入图像说明

理想情况下,将在Splat函数中内置一些数据validation,该函数只会触发/斜杠触发器,否则会通过数据validationpopup窗口。

任何想法如何处理这个,示例代码,文章等将不胜感激。

谢谢。

尝试使用Worksheet_Change事件,如下所示:

 Sub Worksheet_Change(ByVal Target As Range) 'Assume the workbook has a named range 'lookuptable' at G3:H6 'Assume the workbook has a named range 'lookupColumn' at D3:D6 If Target.Cells.Count <> 1 Then Exit Sub If Intersect(Target, Range("lookupColumn")) Is Nothing Then Exit Sub If Not Left(Target, 1) = "/" Then Exit Sub UpdateLookupTable Target End Sub Sub UpdateLookupTable(cl As Range) Dim r As Long Dim c As Long Dim splatVal As String splatVal = Replace(cl.Value, "/", 0, , 1) r = Application.Match(cl.Offset(0, -1), Range("lookuptable").Columns(1), False) Range("lookuptable").Cells(r, 2).Value = splatVal cl.Value = splatVal End Sub 

我不知道你是否打算在列D中保留VLOOKUP公式。这个例子没有,但是如果你想保留这些函数,可以修改它。