VBA syntax question index match

Arie Bos

Board Regular
Joined
Mar 25, 2016
Messages
224
Office Version
  1. 365
Platform
  1. Windows
Hi everyone,

I have the following code creating an error in the syntax of the "TruckType" argument in the Match function. I am not sure if I should use Val(), Me.() or any argument, all gave me an error.

VBA Code:
Dim TruckType As String
    Select Case True
      Case optTruckType11: TruckType = "Truck < 10 ton"
      Case optTruckType21: TruckType = "Truck 10-20 ton"
      Case optTruckType31: TruckType = "Truck > 20 ton"
    End Select

Dim CO2PerTruckload As Double
CO2PerTruckload = WorksheetFunction.Index(Range("CO2_TruckWeightWTW"), _
                  WorksheetFunction.Match(TruckType, Range("CO2_TruckWeight"), 0))
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
May be I should add that
VBA Code:
Range("CO2_TruckWeight")
contains the three items from the Select Case function.
 
Upvote 0
I solved my own question. The code was actually OK, but in a wrong place...
 
Upvote 0
Solution

Forum statistics

Threads
1,215,064
Messages
6,122,942
Members
449,094
Latest member
teemeren

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