+ Reply to Thread
Results 1 to 11 of 11

Populating a column based on previous data in 2 other columns

Hybrid View

  1. #1
    Registered User
    Join Date
    04-26-2010
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    6

    Populating a column based on previous data in 2 other columns

    This is what I've come up with so far;

    =IF(AND(B1=B2,B2=B3),A1&", "&A2&", "&A3, IF(B1=B2,A1&", "&A2, A1))

    It is limited to 3 cells sadly but I need it to work into the thousands.

    What needs to happen is (Please see my data set for you)...

    AEG	79901G-M 	94975062800
    AEG	79901G-M 	94977004600
    ARTHUR MARTIN	AHT6083K 	94962052900
    ARTHUR MARTIN	AHT6083X 	94962053000
    ARTHUR MARTIN	AHT6231K 	94976005900
    ARTHUR MARTIN	AHT6331K 	94974058600
    ARTHUR MARTIN	AHT6421P 	94962045000
    ARTHUR MARTIN	AHT6431K 	94962043900
    ARTHUR MARTIN	AHT6431W 	94962043800
    ARTHUR MARTIN	AHT7531K 	94963022000
    ARTHUR MARTIN	AHT7531W 	94963021900
    FAURE 	CZC6046X 	94774075700
    ARTHUR MARTIN	EHG70830X 	94963032600
    ELECTROLUX 	EHM60335X 	94974059400
    ELECTROLUX 	EHM60335X 	94974059401
    ELECTROLUX 	EHT60235K 	94976006000
    ELECTROLUX 	EHT60235K 	94976006001
    ELECTROLUX 	EHT60235K 	94976006002
    We'll take the spreadsheet for example, it'll where there's a match in B2 and B3, it'll copy C2 and C3 and put in another cell seperated with ", ".

    Ideally resulting in a format similiar to -

    AEG	79901G-M 	94975062800, 94977004600
    ARTHUR MARTIN	AHT6083K 	94962052900
    ARTHUR MARTIN	AHT6083X 	94962053000
    ARTHUR MARTIN	AHT6231K 	94976005900
    ARTHUR MARTIN	AHT6331K 	94974058600
    ARTHUR MARTIN	AHT6421P 	94962045000
    ARTHUR MARTIN	AHT6431K 	94962043900
    ARTHUR MARTIN	AHT6431W 	94962043800
    ARTHUR MARTIN	AHT7531K 	94963022000
    ARTHUR MARTIN	AHT7531W 	94963021900
    FAURE 	CZC6046X 	94774075700
    ARTHUR MARTIN	EHG70830X 	94963032600
    ELECTROLUX 	EHM60335X 	94974059400, 94974059401
    ELECTROLUX 	EHT60235K 	94976006000, 94976006001, 94976006002
    I would honestly give a kidney for any help on the matter.
    Last edited by JJJJ1; 04-27-2010 at 11:43 AM. Reason: Broke the rules :(

  2. #2
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: VB Script or If possible in a macro?

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely 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.
    To change a Title on your post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.

  3. #3
    Registered User
    Join Date
    04-26-2010
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: VB Script or If possible in a macro?

    I hope this is a little more appropriate.
    Last edited by davesexcel; 04-26-2010 at 07:27 PM.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Populating a column based on previous data in 2 other columns

    Much better, thanks.

    Now post a workbook with before and after examples.
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Registered User
    Join Date
    04-26-2010
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Populating a column based on previous data in 2 other columns

    As requested, it's pretty much the same as the text I have posted. I'd appreciate any help on the matter.

    Basically, the idea of this is to build up a list of the serial numbers in third column seperated by ", "
    Attached Files Attached Files

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Populating a column based on previous data in 2 other columns

    Try this:
    Sub x()
        Dim wks         As Worksheet
        Dim r           As Range
        Dim iRow        As Long
        Dim iOfs        As Long
    
        Set wks = Worksheets("Before") ' change as desired
        With wks
            .UsedRange.Sort Key1:=.UsedRange(1), Order1:=xlAscending, _
                            Key2:=.UsedRange(2), Order2:=xlAscending, _
                            Header:=xlNo
            Set r = .Range("A1", .Cells(.Rows.Count, "A").End(xlUp))
            iRow = 1
            
            Do While iRow <= r.Rows.Count + r.Row - 1
                iOfs = 1
                With r(iRow, 1)
                    Do While .Offset(iOfs, 0).Value = .Value And .Offset(iOfs, 1).Value = .Offset(, 1).Value
                        .Offset(, 2).Value = .Offset(, 2).Value & ", " & .Offset(iOfs, 2).Value
                        .Offset(iOfs).EntireRow.ClearContents
                        iOfs = iOfs + 1
                    Loop
                End With
                iRow = iRow + iOfs
            Loop
            .UsedRange.Sort Key1:=.UsedRange(1), Order1:=xlAscending
        End With
    End Sub

  7. #7
    Registered User
    Join Date
    04-26-2010
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Populating a column based on previous data in 2 other columns

    Set wks = Worksheets("Test") ' change as desired
    I've changed it to this with a workbook called Test. In the workbook I open the macro's panel, create new macro and slam it in like normal.

    It is still returning the same error

  8. #8
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Populating a column based on previous data in 2 other columns

    It's not the WORKBOOK name, it's the SHEET name--what you see on the tab.

  9. #9
    Registered User
    Join Date
    04-26-2010
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: Populating a column based on previous data in 2 other columns

    Oh my, thank you and that is working perfectly.

    Something I guess i'll have to check for is where there is a space or double space after something in a column.

    I really appreciate this, thanks again.

+ 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