drop down list in VBA

Blobajob88

Board Regular
Joined
Mar 27, 2020
Messages
55
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi,

Can anyone tell me why the following code won't work:

VBA Code:
Range("M5").Validation.Delete
Range("M5").Validation.Add Type:=xlValidateList AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="Orange,Apple,Mango,Pear,Peach"
Range("m5").Validation.InCellDropdown = True
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
You're missing a comma before AlertStyle
 
Upvote 0
Easily missed, unfortunately. :(
 
Upvote 0
Hi,

This is possibly another silly mistake but now I've changed my table drop down to a range in another sheet but it will only work if that sheet is activated. Is there anything I can add so it doesn't need to be on the sheet called Sheet1?


VBA Code:
Range("M5").Validation.Delete
Range("M5").Validation.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=Sheet1!B4:B8"
Range("M5").Validation.InCellDropdown = True
 
Upvote 0
Do you have a sheet called "Sheet1" as seen on the sheet tab?
 
Upvote 0
Yes

1586802344777.png
 
Upvote 0
Just realised. I had the sheet protected. I unprotected it and it works fine.

One final question - Do you know if you can change the font size of the text within the dropdown so it is clearer without just zooming in?
 
Upvote 0

Forum statistics

Threads
1,215,807
Messages
6,127,005
Members
449,351
Latest member
Sylvine

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