call a macro if value in particular column is either of 2 specific values

  • call a macro if value in particular column is either of 2 specific values



    in this macro, macro copydownwards is called if "D. DUTY" is entered in any cell in column "O"
    i want to extent it for values "SPM DUTY" as well as "D. DUTY"

  • Re: call a macro if value in particular column is either of 2 specific values


    Welcome to the Forum.


    Have you read the Forum Rules?


    All VBA code posted in the forum must be wrapped in code tags, which you omitted, including single-line code snippets.
    Please make an immediate edit of your post to add the missing tags. Be sure to use them in future posts.


    [COLOR="navy"]How to use code tags[/COLOR]


    [noparse]

    Code
    [/noparse]
    [COLOR="navy"]your code goes between these tags[/COLOR]
    [noparse]

    [/noparse]


    Or, just highlight all of the code and press the [COLOR="#FF0000"]#[/COLOR] button to add the code tags.


    Thanks.


    I'll add them this time

  • Re: call a macro if value in particular column is either of 2 specific values


    Code Tags


    Per the board rules please encapsulate any and all vba code in code tags. This helps you and those trying to help you read and understand your code.


    This is so even for a single line code.


    To encapsulates your code in code tags:


    1. Highlight your code
    2. Click on the # icon



    I have added code tages to your posting


    Thank you for your cooperation.

    [FONT="Arial Black"][COLOR="blue"][SIZE="4"]Bill[/SIZE][/COLOR][/FONT]
    Tip: To avoid chasing code always use Option Explicit.

  • Re: call a macro if value in particular column is either of 2 specific values


    This should do what you want :)



    [SIZE=3]The Only Dumb Question Is A Question Not Asked.[/SIZE]

  • Re: call a macro if value in particular column is either of 2 specific values


    Here you go. . .

    [FONT="Arial Black"][COLOR="blue"][SIZE="4"]Bill[/SIZE][/COLOR][/FONT]
    Tip: To avoid chasing code always use Option Explicit.

  • Re: call a macro if value in particular column is either of 2 specific values


    Or this


    Code
    Private Sub Worksheet_SelectionChange(ByVal Target As Range) 
         
       With Target
            If .Count > 1 Or .Count <> 15 Then Exit Sub  
        Select Case .Value 
        Case "D. Duty" , "SPM Duty" 
            Call CopyDownRows   
        End Select 
       End With 
    End Sub
  • Re: call a macro if value in particular column is either of 2 specific values


    Sorry, use this corrected code

    [FONT="Arial Black"][COLOR="blue"][SIZE="4"]Bill[/SIZE][/COLOR][/FONT]
    Tip: To avoid chasing code always use Option Explicit.

  • Re: call a macro if value in particular column is either of 2 specific values


    above code worked for me.thanks once again

Participate now!

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