Vlookup in VBA generating error

JackDanIce

Well-known Member
Joined
Feb 3, 2010
Messages
9,922
Office Version
  1. 365
Platform
  1. Windows
Hi,

I'm trying to condense following:
Code:
    Select Case i
        Case 1 To 3:    ForeCastCol = "A"
        Case 4 To 10:   ForeCastCol = "B"
        Case 11 To 15:  ForeCastCol = "C"
        Case Else:      ForeCastCol = "D" 'Limit is 18 regardless
    End Select
To:
Code:
Application.Vlookup(i, [3, 10, 15, 18], ["A", "B", "C", "D"], True)
Where "A", "B" etc are irrelevant or an equivalent function

Limits of 3, 10, 15 and 18 will never change (and always ascending order) can someone suggest?

TIA,
Jack
 
Last edited:
Try
Code:
    ForeCastCol = Application.Lookup(i, Array(0, 4, 11, 16), Array("Total_", "Practices_", "Central_", "AffL_"))
But I'd agree with shg & stick with the select case
 
Upvote 0

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Cheers @Fluff looks like my limit values needed to change, but yes I went back to Select Case after @shg replied :) was curious as to what the error meant or cause of it, incorrect limit values.
 
Last edited:
Upvote 0
It is @shg? If I revert to that, then won't have these errors...

Thanks for the comment @shg, curious to know why this doesn't work now, but if Select Case is faster (and working) then, will revert.
The lookup will fail if i is less than 3.
 
Upvote 0
Thanks @JoeMo I do need to account for all values 1 - 18, despite buckets - useful to know for next time :)
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,217
Members
453,024
Latest member
Wingit77

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top