+ Reply to Thread
Results 1 to 7 of 7

Data Validation If Statement

Hybrid View

  1. #1
    Registered User
    Join Date
    08-25-2015
    Location
    LA
    MS-Off Ver
    2007
    Posts
    9

    Data Validation If Statement

    Hello,

    I am having difficulties with creating a code or data validation on an if then statement. Currently in C1 I has a list that gives the options "Yes" or "No" and in cells D1, E1, F1 I have manual inputs that feed to a future formula. I would like it so that If C1 = "No" then D1, E1, F1 all equal 0 and if C1 = "Yes" then it just allows for manual input/ or just does nothing. Please let me know if you can help.

    Thanks!

  2. #2
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Data Validation If Statement

    In the visual basic editor, put this code in the section for which ever worksheet this applies to:

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Target.Address = Range("C1").Address Then
        If Target = "No" Then
            Target.Offset(, 1).Resize(1, 3).Value = 0
        End If
    End If
    
    End Sub
    If you are happy with my response please click the * in the lower left of my post.

  3. #3
    Registered User
    Join Date
    08-25-2015
    Location
    LA
    MS-Off Ver
    2007
    Posts
    9

    Re: Data Validation If Statement

    Thank you! That works great what would I change it to if I wanted it to skip over cells D1,E1,F1 have no effect in those and only have it change G1,H1,I1,J1 & K1?

  4. #4
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Data Validation If Statement

    This line establishes the range which the value is set to 0

    Target.Offset(, 1).Resize(1, 3)
    In your scenario Target will always be cell C1. If you want to apply code to cell G1 you would offset by 4 columns (i.e. Target.Offset(,4))
    Then if you want to further expand to cover columns H, I, J, and K you would resize the range appropriately. Ex:

    Target.Offset(, 4).Resize(1, 5).Value = 0

  5. #5
    Registered User
    Join Date
    08-25-2015
    Location
    LA
    MS-Off Ver
    2007
    Posts
    9

    Re: Data Validation If Statement

    Great thank you! I just have two more questions, sorry this model is getting to be more complext than imagined.

    I am trying to copy and paste that code and change it to do the same thing for line C2 and further down however it is not working. Do you know what I have to change to allow the code to do more than just outputs from C1, "Yes" or "No"?

    And my last question is, how can I put it in there that if "Yes" then make cell G1=1, H1=1, I1=500, J1=200, K1=400 and do that for drop box in C2.. C3 etc.

  6. #6
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: Data Validation If Statement

    The macro was written to only work on cell C1 as was indicated in the original post. Below I has supplied a new code to work for any cell in column C and incorporate the newly supplied information.

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    If Not Intersect(Target, Range("C:C")) Is Nothing Then
        If UCase(Target) = "NO" Then
            Target.Offset(, 4).Resize(1, 5).Value = 0
        ElseIf UCase(Target) = "YES" Then
            Target.Offset(, 4) = 1
            Target.Offset(, 5) = 1
            Target.Offset(, 6) = 500
            Target.Offset(, 7) = 200
            Target.Offset(, 8) = 400
        End If
    End If
    
    End Sub

  7. #7
    Registered User
    Join Date
    08-25-2015
    Location
    LA
    MS-Off Ver
    2007
    Posts
    9

    Re: Data Validation If Statement

    Thank you very much for all of your help!!

+ 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. If statement based data validation? Dynamic data validation?
    By bjohnsonac in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-02-2014, 02:12 PM
  2. [SOLVED] Data Validation with AND statement
    By meckenroth in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-13-2014, 12:27 PM
  3. [SOLVED] Data VAlidation With If statement
    By excobra in forum Excel General
    Replies: 6
    Last Post: 11-12-2013, 05:28 AM
  4. Data validation and If statement
    By tjohans in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-29-2013, 05:20 PM
  5. DATA Validation and IF statement
    By NCAA in forum Excel General
    Replies: 3
    Last Post: 03-29-2012, 04:01 AM
  6. Data validation in if statement
    By mahoo in forum Excel General
    Replies: 3
    Last Post: 02-15-2011, 04:06 PM
  7. [SOLVED] using the if statement with data validation
    By GreenMonster in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-16-2005, 04:06 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