+ Reply to Thread
Results 1 to 6 of 6

Macro to Validate data in Column B based on Column A

  1. #1
    Registered User
    Join Date
    11-02-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    5

    Question Macro to Validate data in Column B based on Column A

    Hello!
    I'm trying to create a macro that will check to see if the data the user is inputting is valid for the row.
    For example:

    User will input into Column A2 - "4444" and then SHOULD enter into Column B2 - "3" or "4".
    However* there are times where A2 might have a different value in which B2 will have anything but 3 or 4 entered.

    I'm extremely new to VBA/Excel programming and i'm unsure how to do this so that it checks each row as its being entered.

    If i am being too vague, i apologize and will try to clear anything up.

    Thank you in advance.
    Last edited by Lawliet; 05-03-2013 at 11:05 AM. Reason: Resolved.

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Macro to Validate data in Column B based on Column A

    Lawliet,

    Why not use data validation? You could setup a dependent drop-down list, no VBA required
    Intro to data validation: http://www.contextures.com/xlDataVal01.html
    Making dependent lists: http://www.contextures.com/xlDataVal02.html
    Hope that helps,
    ~tigeravatar

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

  3. #3
    Registered User
    Join Date
    11-02-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Macro to Validate data in Column B based on Column A

    Quote Originally Posted by tigeravatar View Post
    Lawliet,

    Why not use data validation? You could setup a dependent drop-down list, no VBA required
    Intro to data validation: http://www.contextures.com/xlDataVal01.html
    Making dependent lists: http://www.contextures.com/xlDataVal02.html
    The data/worksheet will be put through a different macro/uploaded into various programs and i'm unsure how they would handle that without further manipulation. Also this would need to be able to accept a much wider range of numbers if certain other inputs are used for A2. I apologize for not stating that earlier. Thank you for the suggestion though.
    Last edited by Lawliet; 05-01-2013 at 03:01 PM.

  4. #4
    Registered User
    Join Date
    11-02-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Macro to Validate data in Column B based on Column A

    Bump no response.

    Anyone with any suggestions? I was hoping to be able to use this as a building point for future alterations that i may need as well.

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

    Re: Macro to Validate data in Column B based on Column A

    I'm only so so with VBA but is this what you are looking for? (see attachment)
    code is in worksheet as follows
    Please Login or Register  to view this content.
    I used 3 rules
    if a = 4444 b has to be 3 or 4
    if a is empty then can't fill in b
    if a <> 4444 then b cannot be 3 or 4
    Attached Files Attached Files
    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

  6. #6
    Registered User
    Join Date
    11-02-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: Macro to Validate data in Column B based on Column A

    Thanks a ton ChemistB, that will be great to built it upon and definitely what i was looking for. And thanks even more so by providing a file too showcasing it.

+ 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