Hello, I am new to VB and want to convert my spreadsheet functions into VB code but I am really battling.
Basically I want to use an index function to form an array. I want the array so that I can use it in a match function.
A shortened example of what I thought would work is below, but I must be missing a whole lot of steps:
Function Indextest4(LABL2, ITEM2)
Dim MRange1 As Range
Set MRange1 = Worksheets("Sheet1").Range("A$1:XFD$1048576")
MATC1 = Application.WorksheetFunction.Match(LABL2, MRange2, 0)
INDX1 = Application.WorksheetFunction.Index(MRange1, 1048576, MATC1)
INDX2 = Application.WorksheetFunction.Index(MRange1, 1, MATC1)
'this bit doesn't work:
Dim MRange3 As Range
Set MRange3 = Worksheets("Sheet1").Range(INDX2: INDX1)
Indextest4 = Application.WorksheetFunction.Match(ITEM2, MRange3, 0)
End Function
Obviously the INDX1 and INDX2 are becomming the cell contents rather than cell locations, so while this works when placed on a single line in excel, it doesn't work in VB. Any help with keeping IDEX1 as the cell location would be greatly appreciated.
Basically I want to use an index function to form an array. I want the array so that I can use it in a match function.
A shortened example of what I thought would work is below, but I must be missing a whole lot of steps:
Function Indextest4(LABL2, ITEM2)
Dim MRange1 As Range
Set MRange1 = Worksheets("Sheet1").Range("A$1:XFD$1048576")
MATC1 = Application.WorksheetFunction.Match(LABL2, MRange2, 0)
INDX1 = Application.WorksheetFunction.Index(MRange1, 1048576, MATC1)
INDX2 = Application.WorksheetFunction.Index(MRange1, 1, MATC1)
'this bit doesn't work:
Dim MRange3 As Range
Set MRange3 = Worksheets("Sheet1").Range(INDX2: INDX1)
Indextest4 = Application.WorksheetFunction.Match(ITEM2, MRange3, 0)
End Function
Obviously the INDX1 and INDX2 are becomming the cell contents rather than cell locations, so while this works when placed on a single line in excel, it doesn't work in VB. Any help with keeping IDEX1 as the cell location would be greatly appreciated.