VBA Excel VLOOKUP中的VLOOKUP

时间:2016-07-28 14:24:53

标签: excel-vba vba excel

我正在尝试创建一个VLOOKUP宏,提示用户选择单元格和范围。

基本上我想在一个标签中查找单元格值,而不是另一个标签中的范围,并返回用户选择的列。

所以......这就是我想要的......

VLOOKUP(""USER SELECT LOOKUP value", "USER SELECT TABLE ARRAY", "USER SELECT COL INDEX NUM", FALSE)

到目前为止我有这个,但是当宏完成运行时没有任何回报...

Subject = Application.Input box("select Subject to be looked up")
Sheet = Application.Input box("select tab/range")

          Formula = "=VLOOKUP(""Subject"",""Sheet"",3,False)"

end sub

1 个答案:

答案 0 :(得分:2)

您需要从引号中提取变量并使用CREATE FUNCTION [dbo].[udf-Str-Parse] (@String varchar(max),@Delimeter varchar(10)) --Usage: Select * from [dbo].[udf-Str-Parse]('Dog,Cat,House,Car',',') -- Select * from [dbo].[udf-Str-Parse]('John Cappelletti was here',' ') -- Select * from [dbo].[udf-Str-Parse]('id26,id46|id658,id967','|') -- Select * from [dbo].[udf-Str-Parse]('Kiran,Kiran,Kiran',',') Returns @ReturnTable Table (Key_PS int IDENTITY(1,1) NOT NULL , Key_Value varchar(max)) As Begin Declare @intPos int,@SubStr varchar(max) Set @IntPos = CharIndex(@Delimeter, @String) Set @String = Replace(@String,@Delimeter+@Delimeter,@Delimeter) While @IntPos > 0 Begin Set @SubStr = Substring(@String, 0, @IntPos) Insert into @ReturnTable (Key_Value) values (@SubStr) Set @String = Stuff(@String, 1, Len(@SubStr+@Delimeter), ''); Set @IntPos = CharIndex(@Delimeter, @String) End Insert into @ReturnTable (Key_Value) values (@String) Return End 连接。

你也想让它们成为范围,并在公式中使用它们的地址:

&