Formula finds the name in Col AO in a sheet in a different workbook that matches the name in A5 of the active sheet, and pulls across the matching value from Col AP of the sheet in that other file. Works perfectly.
=IF(A4="","",IF(A5="",SUM(B4:B$5),IFERROR(INDEX(OTHERFILENAME]SHEETNAME!$AP$5:$AP$24,MATCH($A5,'OTHERFILENAME]SHEETNAME'!$AO$5:$AO$24,0)),"")))
But, as the other file name will change each month, need this as a Macro, allowing the end user to select the file
Sub Mergetimes()
Dim vFile As Variant
Dim wbCopyTo As Workbook
Dim wsCopyTo As Worksheet
Dim wbCopyFrom As Workbook
Dim wsCopyFrom As Worksheet
Set wbCopyTo = ActiveWorkbook
Set wsCopyTo = ActiveSheet
'Open file with data to be copied
vFile = Application.GetOpenFilename("Excel Files (*.xl*)," & _
"*.xl*", 1, "Select Excel File", "Open", False)
'If Cancel then Exit
If TypeName(vFile) = "Boolean" Then
Exit Sub
Else
Set wbCopyFrom = Workbooks.Open(vFile)
Set wsCopyFrom = wbCopyFrom.Worksheets(2)
End If
'--------------------------------------------------------------
'This is where the Index Match falls over
'Tried it as a VBA call, but doesn't recognise "Match", for some reason.
Range("B5") = Application.WorksheetFunction.Index(Workbooks([wbCopyFrom]), Worksheets(wsCopyFrom)![AP5:AP24], Application.WorksheetFunction.Match(Range("A5"), Workbooks([wbCopyFrom]), Worksheets(wsCopyFrom)![A05:A024], 0), 1)
'Then tried to convert the formula to accomodate the variable file and sheet names, but can't capture the correct syntax?
Range("B5")="=IF(A4="""","""",IF(A5="""",SUM(B4:B$5),IFERROR(INDEX('"&[wbCopyFrom]&wsCopyFrom!"&AP5:AP24,MATCH(A5,('"&wbCopyFrom&"]&wsCopyFrom'!&AO5:AO24,0)),"")))
Any suggestions or pointers received gratefully as ever
Ochimus
Bookmarks