Results 1 to 7 of 7

Macro for coding an action based on 3 columns of information

Threaded View

  1. #1
    Registered User
    Join Date
    07-16-2008
    Location
    Clarksville, AR
    Posts
    9

    Macro for coding an action based on 3 columns of information

    Hi all,

    I'm doing a very time-consuming coding task that I think can be automated.
    I'm coding errors in a procedural task environment, with the following steps: P, Q, R, S, T, Z,Complete_contract (post), and Next_order (end).
    I want to code the position of an error action relative to its error position.

    I tried writing out the conditionals below. I think they will work; I just need them translated into VBA.

    Sub begins.
    
    Look at cells in a row along column C (trial) column D (error psn) and column E (error action).
    
    If D="P" and E contains "Q", and C contains "nil", then write "1" in column K.
    If D="P" and E contains "Q", and C does not contain "nil", then write "1" in column J.
    If D="P" and E contains "R", and C contains "nil", then write "2" in column K.
    If D="P" and E contains "R", and C does not contain "nil", then write "2" in column J. 
    If D="P" and E contains "S", and C contains "nil", then write "3" in column K.
    If D="P" and E contains "S", and C does not contain "nil", then write "3" in column J.
    If D="P" and E contains "T", and C contains "nil", then write "4" in column K
    If D="P" and E contains "T", and C does not contain "nil", then write "4" in column J.
    If D="P" and E contains "Z", and C contains "nil", then write "5" in column K.
    If D="P" and E contains "Z", and C does not contain "nil", then write "5" in column J.
    If D="P" and E contains "Complete_contract", and C contains "nil", then write "6" in column K.
    If D="P" and E contains "Complete_contract", and C does not contain "nil", then write "6" in column J.
    If D="P" and E contains "Next_order", and C contains "nil", then write "7" in column K.
    If D="P" and E contains "Next_order", and C does not contain "nil", then write "7" in column J.
    If D="P" and E contains "P", do nothing and continue search
    
    If D="Q" and E contains "R", and C contains "nil", then write "1" in column K.
    If D="Q" and E contains "R", and C does not contain "nil", then write "1" in column J.
    If D="Q" and E contains "S", and C contains "nil", then write "2" in column K.
    If D="Q" and E contains "S", and C does not contain "nil", then write "2" in column J.
    If D="Q" and E contains "T", and C contains "nil", then write "3" in column K.
    If D="Q" and E contains "T", and C does not contain "nil", then write "3" in column J.
    If D="Q" and E contains "Z", and C contains "nil", then write "4" in column K.
    If D="Q" and E contains "Z", and C does not contain "nil", then write "4" in column J.
    If D="Q" and E contains "Complete_contract", and C contains "nil", then write "5" in column K.
    If D="Q" and E contains "Complete_contract", and C does not contain "nil", then write "5" in column J.
    If D="Q" and E contains "Next_order", and C contains "nil", then write "6" in column K.
    If D="Q" and E contains "Next_order", and C does not contain "nil", then write "6" in column J.
    If D="Q" and E contains "P", and C contains "nil", then write "-1" in column K.
    If D="Q" and E contains "P", and C does not contain "nil", then write "-1" in column J
    If D="Q" and E contains "Q", do nothing and continue search
    
    If D="R" and E contains "S", and C contains "nil", then write "1" in column K.
    If D="R" and E contains "S", and C does not contain "nil", then write "1" in column J.
    If D="R" and E contains "T", and C contains "nil", then write "2" in column K.
    If D="R" and E contains "T", and C does not contain "nil", then write "2" in column J.
    If D="R" and E contains "Z", and C contains "nil", then write "3" in column K.
    If D="R" and E contains "Z", and C does not contain "nil", then write "3" in column J.
    If D="R" and E contains "Complete_contract", and C contains "nil", then write "4" in column K.
    If D="R" and E contains "Complete_contract", and C does not contain "nil", then write "4" in column J.
    If D="R" and E contains "Next_order", and C contains "nil", then write "5" in column K.
    If D="R" and E contains "Next_order", and C does not contain "nil", then write "5" in column J.
    If D="R" and E contains "Q", and C contains "nil", then write "-1" in column K.
    If D="R" and E contains "Q", and C does not contain "nil", then write "-1" in column J.
    If D="R" and E contains "P", and C contains "nil", then write "-2" in column K.
    If D="R" and E contains "P", and C does not contain "nil", then write "-2" in column J.
    If D="R" and E contains "R", do nothing and continue search
    
    If D="S" and E contains "T", and C contains "nil", then write "1" in column K.
    If D="S" and E contains "T", and C does not contain "nil", then write "1" in column J.
    If D="S" and E contains "Z", and C contains "nil", then write "2" in column K.
    If D="S" and E contains "Z", and C does not contain "nil", then write "2" in column J.
    If D="S" and E contains "Complete_contract", and C contains "nil", then write "3" in column K.
    If D="S" and E contains "Complete_contract", and C does not contain "nil", then write "3" in column J.
    If D="S" and E contains "Next_order", and C contains "nil", then write "4" in column K.
    If D="S" and E contains "Next_order", and C does not contain "nil", then write "4" in column J.
    If D="S" and E contains "R", and C contains "nil", then write "-1" in column K.
    If D="S" and E contains "R", and C does not contain "nil", then write "-1" in column J.
    If D="S" and E contains "Q", and C contains "nil", then write "-2" in column K.
    If D="S" and E contains "Q", and C does not contain "nil", then write "-2" in column J.
    If D="S" and E contains "P", and C contains "nil", then write "-3" in column K.
    If D="S" and E contains "P", and C does not contain "nil", then write "-3" in column J.
    If D="S" and E contains "S", do nothing and continue search
    
    If D="T" and E contains "Z", and C contains "nil", then write "1" in column K.
    If D="T" and E contains "Z", and C does not contain "nil", then write "1" in column J.
    If D="T" and E contains "Complete_contract", and C contains "nil", then write "2" in column K.
    If D="T" and E contains "Complete_contract", and C does not contain "nil", then write "2" in column J.
    If D="T" and E contains "Next_order", and C contains "nil", then write "3" in column K.
    If D="T" and E contains "Next_order", and C does not contain "nil", then write "3" in column J.
    If D="T" and E contains "S", and C contains "nil", then write "-1" in column K.
    If D="T" and E contains "S", and C does not contain "nil", then write "-1" in column J.
    If D="T" and E contains "R", and C contains "nil", then write "-2" in column K.
    If D="T" and E contains "R", and C does not contain "nil", then write "-2" in column J.
    If D="T" and E contains "Q", and C contains "nil", then write "-3" in column K.
    If D="T" and E contains "Q", and C does not contain "nil", then write "-3" in column J.
    If D="T" and E contains "P", and C contains "nil", then write "-4" in column K.
    If D="T" and E contains "P", and C does not contain "nil", then write "-4" in column J.
    If D="T" and E contains "T", do nothing and continue search
    
    If D="Z" and E contains "Complete_contract", and C contains "nil", then write "1" in column K.
    If D="Z" and E contains "Complete_contract", and C does not contain "nil", then write "1" in column J.
    If D="Z" and E contains "Next_order", and C contains "nil", then write "2" in column K.
    If D="Z" and E contains "Next_order", and C does not contain "nil", then write "2" in column J.
    If D="Z" and E contains "T", and C contains "nil", then write "-1" in column K.
    If D="Z" and E contains "T", and C does not contain "nil", then write "-1" in column J.
    If D="Z" and E contains "S", and C contains "nil", then write "-2" in column K.
    If D="Z" and E contains "S", and C does not contain "nil", then write "-2" in column J.
    If D="Z" and E contains "R", and C contains "nil", then write "-3" in column K.
    If D="Z" and E contains "R", and C does not contain "nil", then write "-3" in column J.
    If D="Z" and E contains "Q", and C contains "nil", then write "-4" in column K.
    If D="Z" and E contains "Q", and C does not contain "nil", then write "-4" in column J.
    If D="Z" and E contains "P", and C contains "nil", then write "-5" in column K.
    If D="Z" and E contains "P", and C does not contain "nil", then write "-5" in column J.
    
    If D="post" and E contains "Next_order", and C contains "nil", then write "1" in column K.
    If D="post" and E contains "Next_order", and C does not contain "nil", then write "1" in column J.
    If D="post" and E contains "Z", and C contains "nil", then write "-1" in column K.
    If D="post" and E contains "Z", and C does not contain "nil", then write "-1" in column J.
    If D="post" and E contains "T", and C contains "nil", then write "-2" in column K.
    If D="post" and E contains "T", and C does not contain "nil", then write "-2" in column J.
    If D="post" and E contains "S", and C contains "nil", then write "-3" in column K.
    If D="post" and E contains "S", and C does not contain "nil", then write "-3" in column J.
    If D="post" and E contains "R", and C contains "nil", then write "-4" in column K.
    If D="post" and E contains "R", and C does not contain "nil", then write "-4" in column J
    If D="post" and E contains "Q", and C contains "nil", then write "-5" in column K.
    If D="post" and E contains "Q", and C does not contain "nil", then write "-5" in column J
    If D="post" and E contains "P", and C contains "nil", then write "-6" in column K.
    If D="post" and E contains "P", and C does not contain "nil", then write "-6" in column J.
    
    End sub
    Also, multiple error action cells in column E can be associated with just one cell in columns C and D respectively. I need to write code to make sure that Excel can code those special cases as well.

    A workbook with sheets containing the uncoded and coded data sets are attached for clarity.

    Thanks!

    EL
    Attached Files Attached Files

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