Highest Rated Comments


BaronVonWasteland591 karma

In the meantime, you can use this:

Function VLOOKUP2(Lookup as Variant, DataTable as Range, LookupColumn as Long, ReturnColumn as Long) as Variant
Dim A()
Dim X as Long
A = DataTable
For X = LBound(A) to UBound(A)
    If Lookup = A(X, LookupColumn) Then
        VLOOKUP2 = A(X, ReturnColumn)
        Goto Ending
    End If
Next X
Ending:
Erase A
End Function

It's pretty self explanatory; due to the possibility of needing to go backwards(aka left) of the lookup column, you need to tell Excel which column the lookup column is in. This function only works where the final argument of a normal VLOOKUP would have been False or 0.

BaronVonWasteland368 karma

You know what, you're absolutely right. Although they both do the same thing, Exit For is obviously more eloquent here. I got into the habit of using Gotos in this manner due to the lack of a "Continue For" in larger projects. But when I'm only returning one result, I can simply exit. Thanks for the tip!

BaronVonWasteland33 karma

In case it helps, here's a macro that will toggle calculation and tell you what the new setting is:

Sub ToggleCalc()
Dim myStr as String
Select Case Application.Calculation
    Case -4105 'currently automatic
        Application.Calculation = xlCalculationManual
        myStr = "Manual"
    Case -4135 'currently manual
        Application.Calculation = xlCalculationAutomatic
        myStr = "Automatic"
End Select
MsgBox "Calculation set to " & myStr
End Sub

BaronVonWasteland3 karma

First, I want to thank you for making work fun again.

Second, could you explain a little bit about how Excel sees dates and fractions so that I can understand why things turn out wonky sometimes?

BaronVonWasteland2 karma

Then you can use this instead

Sub WhichCalc()
Dim myStr as String
Select Case Application.Calculation
    Case -4105
        myStr = "Automatic"
    Case -4135 
        myStr = "Manual"
End Select
MsgBox "Calculation is currently " & myStr
End Sub