+ Reply to Thread
Results 1 to 7 of 7

Automatic output based on another column, yet still allowing input if needed

Hybrid View

  1. #1
    Registered User
    Join Date
    12-09-2009
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    61

    Automatic output based on another column, yet still allowing input if needed

    Column A returns either "Yes" or "No". In column B I would like it to automatically return the number 0 if column A is "No", otherwise I would like it to allow me to enter in another whole number. Could someone assist with a macro for this?
    Last edited by dforte; 08-11-2010 at 01:34 PM.

  2. #2
    Forum Contributor
    Join Date
    07-01-2010
    Location
    United States, Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    116

    Re: Automatic output based on another column, yet still allowing input if needed

    I am assuming that when you say "another whole number," that it is somewhere already in your work book. Since I do not know where that information is, I have just left the False answer as your wording. Additionally, this equation only works if there is only "Yes" and "No" in column A:

    =IF(A1="No",0,Another whole number)

    To make the macro just click on developer-->record macro-->then stop it/save it after you have created the equation.

    Hope this helps!

  3. #3
    Registered User
    Join Date
    12-09-2009
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    61

    Re: Automatic output based on another column, yet still allowing input if needed

    I see how the If formula works, but I want it to automatically put 0 if column A is "No" ... otherwise I want it to allow me to enter in any number I choose. Is there a way to allow the False portion of the formula to allow manual entry?

  4. #4
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Automatic output based on another column, yet still allowing input if needed

    You could always overwrite the formulas if you don't protect them. I think you're looking for a spreadsheet event code.

    This code will automatically put a 0 in column B if you type "no" in A. You can still write over it but that can be fixed with Data Validation if you want. This code only works as you are typing in the value (or select the cell and then click inside the formula box (or F2) then enter). Copy the code and right click on the spreadsheet tab >View Code, then paste.

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 1 And Target.Count = 1 Then
        If Target.Value = "No" Then
        
            Target.Offset(0, 1) = 0
            
        End If
    End If
      
    End Sub
    Does that work for you?
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  5. #5
    Registered User
    Join Date
    12-09-2009
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    61

    Re: Automatic output based on another column, yet still allowing input if needed

    This doesn't exactly work. I used column A and B as a reference for explaining, so I am not sure how to modify this code to fit my sheet. I guess a simpler form of what I would like to happen is that if the column with Y/N output is "No", I would like a "0" to appear in the dependent column. Otherwise it would remain blank allowing me to put in any whole number I choose.

  6. #6
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Automatic output based on another column, yet still allowing input if needed

    Where it says "Target.column = 1 that assumes your Y/N are in Col A. change this to 2 for B, 3 for C, ....
    Where it says "Target.Offset(0, 1) ", the 1 represents 1 column to the right. 2 would be 2 columns to the right -2 would be 2 columns to the left, etc.
    So if your Y/n is in D, and you want your 0 in.....
    A then Offset(0,-3)
    E then Offset(0,1)
    G then Offset(0,3)
    Does that make sense?

  7. #7
    Registered User
    Join Date
    12-09-2009
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2007
    Posts
    61

    Re: Automatic output based on another column, yet still allowing input if needed

    It's about the learning... Thank you!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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