Consulting

Results 1 to 4 of 4

Thread: Multiple Columns to Single Column

  1. #1
    VBAX Regular rrtts's Avatar
    Joined
    Sep 2006
    Posts
    61
    Location

    Multiple Columns to Single Column

    In my worksheet, I have about 30 column headings...each with varying amount of cells that contain data below the headings.

    What I'm trying to figure out how to do is copy the headings that have cells that contain data and the actual cells that have data into a single column.

    Obviously the "record macro" isn't going to assist me much with trying to figure out the code to do this...so hopefully one of you brilliant excel/vb programmers can lend a hand.

    I've tried to illustrate what I'm trying to achieve in a worksheet (attached).

    Appreciate any and all help. Thanks a bunch.

  2. #2
    VBAX Tutor
    Joined
    Nov 2006
    Location
    North East Pennsylvania, USA
    Posts
    203
    Location

    MultipleColumnsToSingleColumn

    rrtts,

    Save your workbook as Test.xls

    In TEST.xls put the word AFTER in cell A20

    Copy the following code into a Module in Test.xls


    [vba]

    Option Explicit

    Sub MultipleColumnsToSingleColumn()
    '
    ' MultipleColumnsToSingleColumn Macro
    ' Macro created 12/06/2006 by Stanley D. Grom, Jr.
    '
    '
    Dim lngLastColumn As Long
    Dim c As Long
    Dim r As Long
    Dim m As Long
    m = 21
    Application.ScreenUpdating = False
    Sheets("Sheet1").Cells(2, 1).Select
    lngLastColumn = Sheets("Sheet1").Range("IV2").End(xlToLeft).Column
    For c = 1 To lngLastColumn
    For r = 2 To 18
    If Cells(r, c).Value <> "" Then
    Cells(r, c).Copy Destination:=Cells(m, 1)
    m = m + 1
    End If
    Next r
    Next c
    Application.ScreenUpdating = True
    End Sub

    [/vba]


    Have a great day,
    Stan

    I am using Windows XP Professional SP2 and Excel 2003 SP2.

  3. #3
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    That works pretty slick Stan. I just put your code in the same workbook...made a copy of sheet 1 for reference and it gets pretty close to what the Original poster was trying to accomplish.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  4. #4
    VBAX Regular rrtts's Avatar
    Joined
    Sep 2006
    Posts
    61
    Location
    Zoinks. That is very slick indeed...I think I can make this work for my project.

    Appreciate the help. You rock.

Posting Permissions

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