+ Reply to Thread
Results 1 to 6 of 6

VBA Code: Change event, multiple if's for a range

  1. #1
    Registered User
    Join Date
    05-22-2012
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4

    VBA Code: Change event, multiple if's for a range

    I'm brand new to excel VBA - found some code that works to change the value of one cell based on a single if statement. I'm trying to write something that will have two if statements, and apply to a range.

    Column C contains one of two values - "Base" or "Option"...let's assume there's 10 rows so C1:C10
    Cell A2 will have a pick list for "On" or "Off" - this will be the change event that applies to any of the Options in Column C.

    In D1:D10, I want "Off" to be returned if A2="Off" and the value next to it in column C is "Option".
    If A1 = "On", all the options should return "On" in column D2

    I hope that's clear enough...I have a feeling this will be very simple for someone out there. A file is attached for some visual assistance. Thanks!!!
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,953

    Re: VBA Code: Change event, multiple if's for a range

    Why VBA? Use =IF(AND(A$2="Off",C1="Option"),"Off","On") in C1 and copy down.
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    05-22-2012
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: VBA Code: Change event, multiple if's for a range

    Should have guessed that question was coming. I don't want to use a formula because I want the user to be able to turn on/off individual elements if they choose. If I use a change event via VBA, the user can pick and choose, or just turn all the options on/off in one swipe.

  4. #4
    Registered User
    Join Date
    05-22-2012
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: VBA Code: Change event, multiple if's for a range

    BUMP - anyone have any ideas on how to solve this one yet? Pretty please?

  5. #5
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: VBA Code: Change event, multiple if's for a range

    Hi,

    protonLeah obviously provides a great solution, but if it is a macro you are after.

    Try this.
    Attached Files Attached Files
    Last edited by JapanDave; 06-12-2012 at 03:04 AM. Reason: Attached correct file this time, 3rd time is a charm!
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

  6. #6
    Registered User
    Join Date
    05-22-2012
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: VBA Code: Change event, multiple if's for a range

    THANK YOU JapanDave! That worked perfectly. You rock.

+ Reply to Thread

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