+ Reply to Thread
Results 1 to 6 of 6

Insert value from cell when three conditions in row are met

  1. #1
    Registered User
    Join Date
    09-21-2017
    Location
    Idaho, USA
    MS-Off Ver
    15.33
    Posts
    3

    Insert value from cell when three conditions in row are met

    Hi Thread -- I’m approaching failure in my quest to write an IF/THEN formula in Excel. Doh! I think my logic is there, but I'm searching for the right commands and order of operations.

    IF CELL “A2” MATCHES CELL IN RANGE “DATABASE!A:A”,
    AND IN “ROW WHERE “A2” MATCHES CELL IN RANGE “DATABASE!A:A””, “DATABASE!B$” = 2003,
    AND IN “ROW WHERE “A2” MATCHES CELL IN RANGE “DATABASE!A:A””, “DATABASE!C$” = 1,
    THEN, “=DATABASE!E$” OF THE ROW WHERE “A2” MATCHES CELL IN RANGE “DATABASE!A:A”, ELSE = -99.

    Any and all help is appreciated.

    For context, the reference database contains 10 years of quarterly earnings data for several thousand ID’s, laid out in panel/repeated measures/long format. An ID only includes quarterly earnings data for quarters in which there is a record of earnings. I am working to transpose this reference database into a wide-format database that indicates: (1) if that ID had any earnings for in each of the 40 possible earning quarters; and (2) if yes, what their earnings were. A sample workbook is provided below.
    Last edited by mpoppen; 09-21-2017 at 01:52 PM. Reason: Title was too broad.

  2. #2
    Forum Expert etaf's Avatar
    Join Date
    10-22-2004
    Location
    Wittering, West Sussex, UK
    MS-Off Ver
    365 (Mac OSX) (16.84 (24041420))
    Posts
    8,775

    Re: Formula | Can it be written?

    you probably need to change your question title
    Please read and adhere to these simple rules!

    1. Use concise, accurate thread titles. Your post title should describe your problem, not your anticipated solution. Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.
    i dont follow your question


    Please upload a small clean sample of your data / workbook (not a picture) to the forum, Make sure you have removed any private information, remember this is a public forum and so available to anyone
    We would like to see an example of your data and also a manual mock up of the expected results you want to achieve.

    To attach a file to your post,
    click "Go advanced" (next to quick post),
    scroll down until you see "manage Attachments",
    click that and select "Choose File" (top Left corner).
    Find your file, click "Open" click "upload" click 'close windows" Top Right. click "Submit Reply"

    Once the upload is completed the file name will appear below the input boxes in this window.
    You can then close the window to return to the new post screen.
    Last edited by etaf; 09-21-2017 at 12:29 PM.
    Wayne
    if my assistance has helped, and only if you wish to , there is an "* Add Reputation" on the left hand side - you can add to my reputation here

    If you have a solution to your thread - Please mark your thread solved do the following: >
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  3. #3
    Registered User
    Join Date
    09-21-2017
    Location
    Idaho, USA
    MS-Off Ver
    15.33
    Posts
    3

    Re: Formula | Can it be written?

    Hi Wayne -- Of course. Thank you.

    I've attached a workbook that contains the following three sheets: (1) “Problem” [contains the spreadsheet I’d like to complete]; (2) “AnswerKey” [manual mock up of the expected results I wan’t to achieve]; and (3) “ReferenceSheet” [which contains the data that should be used to create the computations].

    For context, the reference database contains 10 years of quarterly earnings data for several thousand ID’s, laid out in panel/repeated measures/long format. An ID only includes quarterly earnings data for quarters in which there is a record of earnings. I am working to transpose this reference database into a wide-format database that indicates: (1) if that ID had any earnings for in each of the 40 possible earning quarters; and (2) if yes, what their earnings were
    Attached Files Attached Files

  4. #4
    Forum Expert etaf's Avatar
    Join Date
    10-22-2004
    Location
    Wittering, West Sussex, UK
    MS-Off Ver
    365 (Mac OSX) (16.84 (24041420))
    Posts
    8,775

    Re: Insert value from cell when three conditions in row are met

    a pivot table will do this for you

    see attached - sheet called PVT-etaf

    but will not show the -99 - not sure where that comes from
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    09-21-2017
    Location
    Idaho, USA
    MS-Off Ver
    15.33
    Posts
    3

    Re: Insert value from cell when three conditions in row are met

    Thanks, Etaf. I connected with a friend who wrote a macro for me that works. The pivot table is a good idea, but I couldn't get it to populate the "-99" (a variable label I use for missing data), or Quarters when no ID's registered Wages.

    I've attached the .xlsm file for the greater good, which contains the Macro. The basic VB code for the macro looks like this:

    Sub CompareLoop()

    Dim LTotal As Integer
    Dim CTotal As Integer
    Dim CYear As Integer
    Dim CQuarter As Integer

    'Starting Point

    LTotal = 2
    CTotal = 2
    CYear = 2003
    CQuarter = 1
    PrintCell = 8
    Cells(1, PrintCell) = CYear & "_Q" & CQuarter & "Q_Wage"

    While CYear < 2013

    While CQuarter < 5

    While LTotal < 6
    CCell = "G" & LTotal
    IDValue = Range(CCell).Value
    ' MsgBox (IDValue)
    While CTotal < 18
    CCCell = "A" & CTotal
    CYCell = "B" & CTotal
    CQCell = "C" & CTotal
    IDCValue = Range(CCCell).Value
    IDYValue = Range(CYCell).Value
    IDQValue = Range(CQCell).Value
    If (IDValue = IDCValue And CYear = IDYValue And CQuarter = IDQValue) Then
    VCell = "D" & CTotal
    PValue = Range(VCell).Value
    Cells(LTotal, PrintCell) = PValue
    MatchedIT = 1
    End If
    CTotal = CTotal + 1
    Wend
    If (MatchedIT <> 1) Then
    Cells(LTotal, PrintCell) = -99
    Else
    MatchedIT = 0
    End If
    CTotal = 2
    LTotal = LTotal + 1

    Wend
    LTotal = 2
    CQuarter = CQuarter + 1
    If (CQuarter < 5) Then
    PrintCell = PrintCell + 1
    Cells(1, PrintCell) = CYear & "_Q" & CQuarter & "Q_Wage"
    End If
    Wend

    CQuarter = 1
    CYear = CYear + 1
    PrintCell = PrintCell + 1
    Cells(1, PrintCell) = CYear & "_Q" & CQuarter & "Q_Wage"

    Wend


    End Sub

    Thanks for everyone's help. Great forum.
    Attached Files Attached Files

  6. #6
    Forum Expert etaf's Avatar
    Join Date
    10-22-2004
    Location
    Wittering, West Sussex, UK
    MS-Off Ver
    365 (Mac OSX) (16.84 (24041420))
    Posts
    8,775

    Re: Insert value from cell when three conditions in row are met

    i'm afraid i dont work with VBA here - sorry

+ 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. [SOLVED] Can an IF formula in a cell be written as VBA
    By deek in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-18-2014, 12:30 PM
  2. [SOLVED] Formula written as Macro
    By ALEZI in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-11-2013, 10:28 AM
  3. Array formula that uses last written cell
    By dcguerra in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-01-2013, 03:16 PM
  4. formula's value written to clipBoard
    By bstubbs in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-04-2009, 07:58 PM
  5. input box value into formula written with VBA
    By jcgroove in forum Excel General
    Replies: 1
    Last Post: 06-09-2009, 07:34 PM
  6. Pre-written formula
    By Newton1234 in forum Excel General
    Replies: 2
    Last Post: 06-05-2008, 04:51 AM

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