简体   繁体   中英

VBA - Worksheet activate macro

I have a dropdownlist on a spreadsheet which has a macro when particular items are selected. Eg if they choose "Yes", some cells are unhidden.

I am trying to update this value using VBA, eg SheetName.Range("OptionDropDown").value = "Yes"

when this runs I want also the activation on the worksheet to run, however it just inputs the value but does not run the macro behind it to unhide the sheets. I've tried turning on/off autocalc with no luck. If I go into the spreadsheet and press enter on the cell the macro works

If this needs to trigger each time the dropdown item is changed, I would suggest using the worksheet_change function.

in the sheets VBA page (Terminology isn't great, sorry!)

sub worksheet_change(ByVal Target as Range)

if instr(1,target.address,"letter of column effected"),1)>0 then

     'run code here
else
'Do nothing or other stuff
End if

This will trigger each time a cell changes, which in this instance would be the cell linked to the dropdown box or the cell set to pull a value based on the drop down.

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM