Results 1 to 3 of 3

Thread: Generate data from 3 different columns

  1. #1

    Generate data from 3 different columns

    Register for a FREE account, and/
    or Log in to avoid these ads!

    Column A

    Column B

    Column C

    I want to combine the data and generate all possible combinations such as
    acne treatment mumbai
    acne treatment delhi
    acne treatment chennai
    acne treatment ahmedabad
    acne treatment pune etc..

    pimple treatment mumbai
    pimple treatment delhi
    pimple treatment chennai
    pimple treatment ahmedabad etc..

    how do I do it in Excel 2003?
    What is the formula I should use so that I do not have to do manually?

    Thanks in advance for help

  2. #2
    Administrator Ken Puls's Avatar
    Join Date
    Mar 2011
    Nanaimo, BC, Canada
    Blog Entries
    Excel Version
    Excel Office 365 Insider
    Personally, I'd use a macro for this. Assuming that your data table is in columns A, B and C of Sheet1, starting in Row 2, this should work:

    Sub BuildList()
        Dim wsSource As Worksheet
        Dim wsTarget As Worksheet
        Dim x As Long
        Dim y As Long
        Dim z As Long
        Dim lCount As Long
        Set wsSource = Worksheets("Sheet1")
        Set wsTarget = Worksheets("Sheet2")
        With wsSource
            For x = 2 To .Range("A" & .Rows.Count).End(xlUp).Row
                For y = 2 To .Range("B" & .Rows.Count).End(xlUp).Row
                    For z = 2 To .Range("C" & .Rows.Count).End(xlUp).Row
                        wsTarget.Range("A1").Offset(lCount, 0).Value = _
                            .Cells(x, 1).Value & " " & .Cells(y, 2).Value & " " & .Cells(z, 3).Value
                        lCount = lCount + 1
                    Next z
                Next y
            Next x
        End With
    End Sub
    Ken Puls, FCPA, FCMA, MS MVP

    Learn to Master Your Data at the Power Query Academy (the world's most comprehensive online Power Query training), with my book M is for Data Monkey, or our new Power Query Recipe cards!

    Main Site: -||- Blog: -||- Forums:
    Check out the Excelguru Facebook Fan Page -||- Follow Me on Twitter

    If you've been given VBA code (a macro) for your solution, but don't know where to put it, CLICK HERE.

  3. #3
    Hello Ken,

    Your Macro has saved a lot of time for me.. Thanks a lot..

    I have another situation..

    Sometimes I have data in column D & sometimes in column D + column E..

    How do I get the results of these combinations?

    Thanks in advance

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts