miless2111s
Active Member
- Joined
- Feb 10, 2016
- Messages
- 273
Whilst running some test code to work out which is quicker between vlookups and match/offset (see my other thread) I found that I'd caused some sort of odd effect... Within my code I often set up a reference to a named range so that I can use this (for instance in a vlookup) and this has previously worked fine. However I was then finding that my normal method was apparently randomly failing to actually set the range up and so the calculation was failing.
What I normally do:
This was apparently failing to store or find the MS_Data range and so was causing an error or returning a blank as it didn't know what I was asking it to look in.
However another range, called in the way was working!
I solved this by activating the sheet where the range is located:
as I am such a beginner at this I wonder if I have broken some sort of rule or had I just got lucky all the other times?
Many thanks for any guidance or suggestions as I really can't cope with the idea that the code can appear to behave randomly as I know it can't and it must be user error!
Miles
What I normally do:
Code:
Dim MS_Data As Range
Set MS_Data = Range("MS_Data")
Start = Application.WorksheetFunction.VLookup(Vref, MS_Data, 2, False)
This was apparently failing to store or find the MS_Data range and so was causing an error or returning a blank as it didn't know what I was asking it to look in.
However another range, called in the way was working!
I solved this by activating the sheet where the range is located:
Code:
Dim MS_Data As Range
Worksheets("MS Project Bars Import").Activate
Set MS_Data = Range("MS_Data")
Start = Application.WorksheetFunction.VLookup(Vref, MS_Data, 2, False)
as I am such a beginner at this I wonder if I have broken some sort of rule or had I just got lucky all the other times?
Many thanks for any guidance or suggestions as I really can't cope with the idea that the code can appear to behave randomly as I know it can't and it must be user error!
Miles