Run Macro On Value Being Entered

  • Re: Macro To Run On Cell Answer


    Hi,


    Put this in the worksheet change event in your worksheet module for help hover over the word code.


    Code
    Private Sub Worksheet_Change(ByVal Target As Range)
    If ActiveSheet.Range("B2").Value = "Yes" Then Call MyMacro
    End Sub


    What does your macro consist of perhaps it could be incoroporated into the worksheet change event.

  • Re: Macro To Run On Cell Answer


    Reafidy thanks but i dont think i explained correctly


    I want to run a macro when cell b2 is = to “yes” in worksheet called “Charity Helpers” which hides a column "AF" in sheet called "feb" this is "hidemacro"


    and then reverses it if the answer is "no" or blank this is "unhidemacro"
    i have recorded these and if i run them manualy on there own they work perfect



  • Re: Macro To Run On Cell Answer


    Code
    Private Sub Worksheet_Change(ByVal Target As Range)
    
    
        If Target = "Yes" Then
            Run "hidemacro"
        ElseIf Target = "No" Then
            Run "unhidemacro"
        End If
          
    End Sub
  • Re: Macro To Run On Cell Answer


    Hi there,


    Put something like this in the worksheet code itself (not in a module). The code will run and call your macros depending on what the value is in B2



    Regards,
    Averil

    -------------
    [FONT="Comic Sans MS"]Averil Pretty[/FONT]

  • Re: Run Macro On Certain Value Being Entered In Cell


    Thanks to Averil and Dave


    Averil i have put your code into my worksheet called "Carity Helpers" this is the work sheet where cell "b2" has to be yes or no, the work sheet which where i want to use the hide macros is called "events" what is happening is the hide macros are hiding the columns in "charity Helpers" not "events" it must be my code that is wrong could you please show me how to run my code on specific worksheet only, "hidemacro" And "unhidemacro"


    Thanks


    Regards John

  • Re: Run Macro On Certain Value Being Entered In Cell


    Here is you unhide macro which you want to run on the events worksheet.


    Note there is no select.


  • Re: Run Macro On Certain Value Being Entered In Cell


    Averil thanks for showing me how to get the code to work only on "events" worksheet,
    but the code you did for me to put into the "charity Helpers" worksheet will not work when i input yes or no in cell b2 is it because im using a drop down data validation


  • Re: Run Macro On Certain Value Being Entered In Cell


    To all, check out the BorderAround Method to save a lot of code lines.


    John, the closing code tag is [noparse][/code][/noparse] not [code/]

  • Re: Run Macro On Certain Value Being Entered In Cell


    Thanks Dave - I never knew about the BorderAround method!


    John,


    I have tested this on my computer and seems to work fine. I have this code in a module:



    And the earlier code in the "Charity Workers" sheet:



    If you like, I can post the file I have been working on.


    Cheers,
    Averil

    -------------
    [FONT="Comic Sans MS"]Averil Pretty[/FONT]

  • Re: Run Macro On Certain Value Being Entered In Cell


    Averil,
    You are not turning screenupdating back on.


    John,
    I didnt suggest the borderaround because it was difficult to see what you are actually trying to do, it looked to me like you where trying to put borders around AE3 as well as D3 and D3:AF3. I just cut the code you already had down as to not cause errors.

  • Re: Run Macro On Certain Value Being Entered In Cell


    Kia ora!


    Oops, didn't realise I'd forgotten to turn it back on... thanks for picking that up!


    Cheers,
    Averil

    -------------
    [FONT="Comic Sans MS"]Averil Pretty[/FONT]

  • Re: Run Macro On Certain Value Being Entered In Cell


    Thanks Averil and Dave


    i have done everything you have both said but it still not working would it be something like the format of cell b2 in charity workers ???


    Averil could you post the file please


    Thanks Again to you both


    Regards


    John

  • Re: Run Macro On Value Being Entered


    Hi John,


    Sorry, I have been away on holiday. I hope Dave's file has helped you?


    Regards,
    Averil

    -------------
    [FONT="Comic Sans MS"]Averil Pretty[/FONT]

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!