I'm trying to do two things, and somewhere between them I'm doing something wrong.
(1) I open an Excel file using the following code; I first set the active workbook to a variable, then open the second workbook and set it equal to another variable. This is so that I can reference each 'on the fly' using my code name instead of trying to figure out which one is active at any given time:
'save the workbook and worksheet that was active when the code was called
SummaryWB = Application.ActiveWorkbook
SummaryWS = Application.ActiveWorkbook.ActiveSheet
'{do other stuff- deleted to save space}
Workbooks.Open Filename:=FName ', ReadOnly:=True
DoEvents
Set SourceWB = ActiveWorkbook
'confirmed with a debug.print SourceWB.name - this shows the selected workbook name in the debug window
(2) Then, I want to assign some worksheet ranges to some variables so I can use application.match against them. I know I've done this at a previous employer, but I can't get the syntax right, and I no longer have access to that code base. It should be something like:
SourceList1 = SourceWB.Sheet1.Range("A1:A500").Value
but after processing that line, the VBE tells me that SourceList1 is 'empty' (on mouseover). For some reason, it isn't filling setting my variable to that range. I've also tried variations such as
Set SourceList1 = SourceWB.Sheet1.Range("A1:A500").Value
Set SourceList1 = SourceWB.Sheet1.Range("A1:A500")
SourceList1 = SourceWB.Sheet1.Range("A1:A500")
but so far, nothing seems to work and I'm not sure if the problem is here, or my original assignment of the workbook name. Can anyone provide any hints or insights?
Many thanks,
Keith
Bookmarks