+ Reply to Thread
Results 1 to 12 of 12

Call macro depending on cell link of a Form Control Box

  1. #1
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Call macro depending on cell link of a Form Control Box

    Hi all,

    Can anyone help me simplify below code? I'm trying to run a certain Macro depending on which prefecture was selected within my Form Control Combo Box. Though, I don't want to write 48 macros for every (!) prefecture in my list. Is there an easier way to do it?

    Please Login or Register  to view this content.
    Maybe make the code more flexible and have it check the prefecture name from the Form Control cell link? All macros are the same, only the prefecture shape name changes...

    Please Login or Register  to view this content.

  2. #2
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Call macro depending on cell link of a Form Control Box

    What about this?
    Please Login or Register  to view this content.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  3. #3
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Re: Call macro depending on cell link of a Form Control Box

    'run time error 13' Type mismatch...

  4. #4
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Call macro depending on cell link of a Form Control Box

    Which line gets highlighted when you click on debug on error window?
    Can you post a sample workbook to work with?

  5. #5
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Re: Call macro depending on cell link of a Form Control Box

    If I type

    Please Login or Register  to view this content.
    instead, then the first part works but

    Please Login or Register  to view this content.
    is highlighted and the error 'The item with the specific name wasn't found' appears...

    code.PNG

  6. #6
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Call macro depending on cell link of a Form Control Box

    Oops....

    It should be like this...

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Re: Call macro depending on cell link of a Form Control Box

    Still doesn't seem to work. Though, I think I know why...

    'str' is referring to the Form Control value, rather than its name, correct me if I'm wrong? Though, I need the code to look for the shape name e.g. "Hokkaido" rather than shape name "9".
    I have just included an Index formula to get the currently selected prefecture

    Please Login or Register  to view this content.
    where X48 is the Form Control cell link and W48:W95 the prefecture list

    and have named the range "Selected_Prefecture"

    How would the second part of the code based on the above look like? Something like the below?

    Please Login or Register  to view this content.

  8. #8
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Call macro depending on cell link of a Form Control Box

    What kind of ComboBox that is?
    If you have ActiveX ComboBox, you can get the selected item by referring to its value.
    So the following one would work...

    Please Login or Register  to view this content.
    Here Me refers to the Sheet14 where the ComboBox is supposed to sit.

  9. #9
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Re: Call macro depending on cell link of a Form Control Box

    I'm using a Form Control ComboBox as mentioned above, so I guess your code suggestion does not apply?

  10. #10
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Call macro depending on cell link of a Form Control Box

    Okay in that case, try this and see if it works for you...

    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    07-13-2017
    Location
    Hong Kong
    MS-Off Ver
    MS Office 365
    Posts
    481

    Re: Call macro depending on cell link of a Form Control Box

    That works!! Thanks!

  12. #12
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,649

    Re: Call macro depending on cell link of a Form Control Box

    You're welcome!
    Thanks for the feedback.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Link Form Control Button to Cell Location?
    By bennetas in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-22-2016, 07:48 AM
  2. Replies: 5
    Last Post: 09-09-2016, 05:04 PM
  3. Add Macro to Call Subs Depending on Cell Value
    By John Maier in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-16-2014, 10:45 AM
  4. [SOLVED] How to link form control dropdown box to formula cell
    By warriorpoet7176 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 03-09-2014, 11:03 AM
  5. [SOLVED] Call Form Control Option Button within an If statement
    By SonOfOdin in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-03-2012, 02:23 PM
  6. Changing Cell Link for Check Box Form Control
    By fervorking in forum Excel General
    Replies: 2
    Last Post: 09-02-2011, 03:12 PM
  7. Form Control losing cell link value
    By basaks in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-26-2011, 03:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1