choose in vba

MetLife

Active Member
Joined
Jul 2, 2012
Messages
334
Office Version
  1. 365
Hi,

I want to use the choose function in VBA, but it doesn't seem to be working.

my code...

xx = Application.Worksheet.Choose(1, "3", "4", "5")

thanks
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Try

Either
xx = Application.Choose(1, "3", "4", "5")
or
xx = WorksheetFunction.Choose(1, "3", "4", "5")

M.
 
Upvote 0
sorry, I got mixed up...

srate1m = Application.WorksheetFunction.Choose(2 + CODE, 0.645, 0.763, 0.488, 0.561, 0.407)
 
Upvote 0
Worked for me
Code:
Code = 1
srate1m = Application.WorksheetFunction.Choose(2 + Code, 0.645, 0.763, 0.488, 0.561, 0.407)
MsgBox srate1m 'displays 0.488 as expected - the 3rd element

Probably, in your case, CODE +2 is not in the range 1 to 5. Check the value of the variable CODE

M.
 
Upvote 0
Not sure if there's a difference or not, but you can use the VBA choose function
Code:
Code = 1
srate1m = Choose(2 + Code, 0.645, 0.763, 0.488, 0.561, 0.407)
MsgBox srate1m 'displays 0.488 as expected - the 3rd element
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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