我想使用WorksheetFunction.Match函数,需要加载一个区域。
Row = WorksheetFunction.Match(country, Countries, 0)
你能帮我构建一下Countries变量吗? 我尝试了很多方法(包括下面的方法)但似乎没有任何方法......
Countries = Workbooks("PERSONAL.XLSB").sheets("Sheet1").Range("B:B")
Countries = Worksheets("PERSONAL.XLSB!Sheet1").Range("B:B")
Countries = Worksheets.Range("PERSONAL.XLSB.Sheet1!B:B") ...
我也尝试了上面的一些“Set”,但这也没有帮助......
答案 0 :(得分:0)
我使用下面的代码,它运行正常。你有一个PERSONAL.XLSB文件,当你启动Excel时,它正在加载和隐藏?什么是错误消息 - 它是否超出范围?
Public Sub test()
Dim r As Integer
Dim Countries As Range
Dim Country As Range
Set Countries = Workbooks("PERSONAL.XLSB").Worksheets("Sheet1").Range("C1:C8")
Set Country = Workbooks("PERSONAL.XLSB").Worksheets("Sheet1").Range("A1")
r = WorksheetFunction.Match(Country, Countries, 0)
MsgBox (r)
End Sub
答案 1 :(得分:0)
好的问题解决了,谢谢戴夫!
我实际上将它用作返回国家所属“区域”的函数:
Function AreaEMEA(Country As String)
Dim Countries As Range
Dim Areas As Range
Set Countries = Workbooks("PERSONAL.XLSB").Worksheets("Sheet1").Range("B:B")
Set Areas = Workbooks("PERSONAL.XLSB").Worksheets("Sheet1").Range("A:A")
Row = WorksheetFunction.Match(Country, Countries, 0)
AreaEMEA = WorksheetFunction.Index(Areas, Row)
End Function
我打电话使用
"=PERSONAL.XLSB!Module1.areaemea(A1)"