+ Reply to Thread
Results 1 to 7 of 7

Run macro based on cell

  1. #1
    Forum Contributor
    Join Date
    04-21-2009
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    710

    Run macro based on cell

    Hi There, I would like to run a macro with the code

    Please Login or Register  to view this content.
    if the vale of cell A2 contains the word "round".

    Please advise what code I would need to check if A2 contained the word "round" (it maybe as 12.round, 3.round etc etc), and if it does to run the code above, if it doesn't end the macro

    Thanks in advance

  2. #2
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: Run macro based on cell

    See if this helps:

    Please Login or Register  to view this content.
    Perhaps it was the Noid who should have avoided me...
    If you are satisfied with my solution click the small star icon on the left. Thanks
    1. Make a copy of your workbook and run the following code on your copy (just in case)
    2. With excel open, press ALT+F11 to open the Visual Basic Editor (VBE). From the "Insert" menu, select "Module".
    3. Paste the code from above into the empty white space. Close the VBE.
    4. From the developer tab, choose "Macros", select the Sub Name, and click "Run".

  3. #3
    Forum Contributor
    Join Date
    04-21-2009
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    710

    Re: Run macro based on cell

    Hi there, It does - but it was my mistake, I wanted the code to run if the cell "didn't" contain the word "round" so do I just insert <> somewhere?

    Thanks in advance

  4. #4
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: Run macro based on cell

    Just put the word NOT in front of InStr.

  5. #5
    Forum Contributor
    Join Date
    04-21-2009
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    710

    Re: Run macro based on cell

    Hi there, no it doesn't appear to work.

    Just to clarify after my earlier confusion, if the word "round" is found in cell A2 - do nothing
    If the word "round" is not found in cell A2 then run the code as above

  6. #6
    Valued Forum Contributor AlvaroSiza's Avatar
    Join Date
    09-19-2007
    Location
    Staffordshire
    MS-Off Ver
    2007
    Posts
    591

    Re: Run macro based on cell

    My bad...

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    04-21-2009
    Location
    England
    MS-Off Ver
    Excel 2016
    Posts
    710

    Re: Run macro based on cell

    Thats great thank you

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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