BayEnder111
New Member
- Joined
- Feb 22, 2013
- Messages
- 12
Hi All,
A bit of a strange one here and I may be approaching it completely in the wrong way but....
I'm trying to perform a Vlookup in VBA from my main workbook against another workbook, however this workbooks name changes each week. Therefore I've created some code to look for the word "Open" in a folder path and open the workbook with this in.
Due to this workbook never having a set name I've defined the workbook, sheet and range so I can reference it in the Vlookup.
In my main workbook I've created a loop to go through a range of cells (D2:D2500) and if they aren't blank perform the vlookup. The Cell Offset is used to determine which cell to output the result to.
I'm getting a type mismatch error when I perform the below:
Any help would be greatly appreciated.
Thanks.
A bit of a strange one here and I may be approaching it completely in the wrong way but....
I'm trying to perform a Vlookup in VBA from my main workbook against another workbook, however this workbooks name changes each week. Therefore I've created some code to look for the word "Open" in a folder path and open the workbook with this in.
Due to this workbook never having a set name I've defined the workbook, sheet and range so I can reference it in the Vlookup.
In my main workbook I've created a loop to go through a range of cells (D2:D2500) and if they aren't blank perform the vlookup. The Cell Offset is used to determine which cell to output the result to.
I'm getting a type mismatch error when I perform the below:
Code:
strPath = "C:\Users\\Desktop\Automator" strFile = Dir(strPath & "\" & "*Open*" & ".xls")
If Len(strFile) > 0 Then
Workbooks.Open strPath & "\" & strFile
Sheets(2).Select
myFileName = ActiveWorkbook.Name
mySheetName = ActiveSheet.Name
myRangeName = Range("E3:AP2500")
ThisWorkbook.Activate
Set rng = Range("D2:D2500")
For Each Cell In rng
If Cell.Value <> "" Then
Cell.Offset(0, 15).Value = "=VLOOKUP(C2,[" & myFileName & "]" & mySheetName & "!" & myRangeName & ",2,False)"
End If
Next
Else
MsgBox "Error: Open Problem Lifecycle Not Found": Exit Sub
End If
Any help would be greatly appreciated.
Thanks.