I'm using a function to set a variable:
Dim LastMemRow As Integer
Dim FLAGFileNo As Integer
Dim MemNoRow As Integer
MemNoRow = WorksheetFunction.Match(FLAGFileNo, Workbooks(TalkRegTempFile).Worksheets("Setup Sheet").Range("A1", "A2000"), 0)
Which works fine, however I want to replace "A2000" with a variable LastMemRow (previously set by some earlier code) so that the Match only searches to the last used row in col A of the target worksheet. I've tried this:
MemNoRow = WorksheetFunction.Match(FLAGFileNo, Workbooks(TalkRegTempFile).Worksheets("Setup Sheet").Range(Cells(1, 1), Cells(1, LastMemRow)), 0)
and although the FLAGFileNo and LastMemRow variables contain the expected values, MemNoRow is always 0.
Maybe I can't use Cells in this way in a worksheet function? (Excel 2010)
LastMemRowwhen your code executes?Workbooks(TalkRegTempFile).Worksheets("Setup Sheet").Range(Cells(1, 1).address, Cells(1, LastMemRow).Address)