+ Reply to Thread
Results 1 to 4 of 4

VBA code to calculate cell contents based on another cell value?

  1. #1
    Registered User
    Join Date
    02-11-2010
    Location
    UK
    MS-Off Ver
    Excel 2000 / 2007
    Posts
    11

    VBA code to calculate cell contents based on another cell value?

    Hi all,

    I have a worksheet containing data where row 1 is the column headings, and subsequent rows contain data about individuals with one row per person.

    One of the columns contains the title "age", and I need to pick up this column and insert two columns after it, titled "age_low" and "age_high" which will simply contain a Y or N in each, depending on whether the person's age falls into the low bracket or the high bracket.

    The code below is what I've got so far. I can find the "age" cell no problem and insert columns, but I'm a bit stuck at the tricker bit of saying "if value in the cell in the column titled "age" is between x and y, then the value of this cell is 'Y', else the value of this cell is 'N'".
    Please Login or Register  to view this content.
    Any pointers on where to go from here would be much appreciated!

  2. #2
    Forum Contributor
    Join Date
    02-04-2010
    Location
    Hertfordshire, England
    MS-Off Ver
    Office 2007 (home) Office 365 (work)
    Posts
    134

    Re: VBA code to calculate cell contents based on another cell value?

    Hi

    I added some extra code to your existing code to do the check on the age. You may need to revise to your requirements.

    Please Login or Register  to view this content.
    Hope this helps
    Last edited by excelxx; 02-19-2010 at 12:14 PM. Reason: slight error in code!

  3. #3
    Registered User
    Join Date
    08-10-2006
    Posts
    58

    Re: VBA code to calculate cell contents based on another cell value?

    You could simply use the min and max worksheet functions in your code. Try adding this code in at the beginning (note that this assumes the ages are in column C:

    Please Login or Register  to view this content.
    Then simply add in code as you are evaluating each row that says
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    02-11-2010
    Location
    UK
    MS-Off Ver
    Excel 2000 / 2007
    Posts
    11

    Re: VBA code to calculate cell contents based on another cell value?

    Many thanks for the replies. I've been tied up with other stuff lately but will experiment with the suggested code when I get the chance.

+ 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