1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Excel Macro Copy Data From Columns

Discussion in 'Business Applications' started by computerman29642, Mar 13, 2009.

Thread Status:
Not open for further replies.
Advertisement
  1. computerman29642

    computerman29642 Thread Starter

    Joined:
    Dec 4, 2007
    Messages:
    2,895
    What would be the best way to find a specific Column Header, and copy the data found in the column until the column header is found again?
     
  2. slurpee55

    slurpee55

    Joined:
    Oct 20, 2004
    Messages:
    7,837
    One worksheet? One workbook? A little more info, Cman. You might be able to do what you are asking with formulas.
     
  3. Rollin_Again

    Rollin_Again

    Joined:
    Sep 4, 2003
    Messages:
    4,912
    It would help to post a sample workbook so we can visualize what you are talking about.

    Regards,
    Rollin
     
  4. Zack Barresse

    Zack Barresse

    Joined:
    Jul 25, 2004
    Messages:
    5,452
    I *think* I know what you're talking about. Play around with this code I modified from something I had a while ago..

    Code:
    Option Explicit
    
    Public Sub CopyColumns()
        Dim wb As Workbook, ws As Worksheet, wsDest As Worksheet
        Dim rLook As Range, rCell As Range, sCell As String
        Dim iCnt As Long, sFirstAddy As String
        Const strColHead As String = "List 1" 'your column header
        Set wb = ThisWorkbook
        Set ws = wb.Worksheets(1)
        Set rLook = ws.Rows(1)
        Set rCell = rLook.Find(what:=strColHead, after:=rLook.Cells(rLook.Rows.Count, rLook.Columns.Count), searchdirection:=xlNext, MatchCase:=True)
        sCell = rCell.Address
        iCnt = 1
        Set wsDest = wb.Worksheets.Add(after:=ws)
        Do Until sCell = vbNullString Or sCell = sFirstAddy
            If sFirstAddy = vbNullString Then sFirstAddy = sCell
            ws.Columns(rCell.Column).Copy Destination:=wsDest.Columns(iCnt)
            iCnt = iCnt + 1
            sCell = vbNullString
            Set rCell = rLook.FindNext(after:=rCell)
            sCell = rCell.Address
        Loop
        Application.CutCopyMode = False
    End Sub
    HTH
     
  5. computerman29642

    computerman29642 Thread Starter

    Joined:
    Dec 4, 2007
    Messages:
    2,895
    Sorry Slurpee. I am dealing with only one worksheet and one workbook (when dealing with this issue).
     
  6. computerman29642

    computerman29642 Thread Starter

    Joined:
    Dec 4, 2007
    Messages:
    2,895
    I believe I may have the issue resolved. However, if I determine that the issue remains I will attach a copy of the workbook.

    Thansk Rollin. :)
     
  7. computerman29642

    computerman29642 Thread Starter

    Joined:
    Dec 4, 2007
    Messages:
    2,895
    Zack, thanks for the code. I will play around with the code to see if I can get it to work for me.
     
  8. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/809137

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice