+ Reply to Thread
Results 1 to 11 of 11

Move data to cell sheets

Hybrid View

  1. #1
    Registered User
    Join Date
    11-21-2008
    Location
    Toronto Ontario
    Posts
    5

    Move data to cell sheets

    Basically what I would like the program to do is take the name in A1 and put the rest of that row in a separate sheet called that name. Will also need to check if sheet exits since new people are being added. Data will continue to come in that format and need to be placed into the sheets, the program also needs to put the data in order.

    thanks for help in advance
    Attached Files Attached Files

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    You want to add a sheet named as the value in A1, containing that row?

    What about the other names?
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    11-21-2008
    Location
    Toronto Ontario
    Posts
    5
    I need it to look like this. The other names need their own sheet. After I will be placing other data and it needs to add to the same name or create a new sheet with that name. (i.e with verett the macro would check to see if it exits and then make a new sheet.)
    Attached Files Attached Files

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Do you want a sheet for each name

    Option Explicit
    
    Function WksExists(wksName As String) As Boolean
        On Error Resume Next
        WksExists = CBool(Len(Worksheets(wksName).Name) > 0)
    End Function
    
    Sub moveRow()
        Dim aWs    As Worksheet
        Dim rng    As Range
        Dim cl     As Range
        Dim sShtNm As String
    
        Set aWs = Sheets("Sheet1")
        With aWs
            Set rng = .Range(.Cells(1, 1), .Cells(.Rows.Count, 1).End(xlUp))
            For Each cl In rng
                sShtNm = cl.Value
                If Not WksExists(sShtNm) Then
                    Sheets.Add
                    ActiveSheet.Name = sShtNm
                    cl.EntireRow.Copy Sheets(sShtNm).Cells(1, 1)
                End If
            Next cl
        End With
    End Sub

  5. #5
    Registered User
    Join Date
    11-21-2008
    Location
    Toronto Ontario
    Posts
    5
    yes i do, and thank you for your help.

  6. #6
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Please mark the thread solved & rate the answer.

  7. #7
    Registered User
    Join Date
    11-21-2008
    Location
    Toronto Ontario
    Posts
    5
    that is alot closer then I got with hours of thinking. How could i get the macro to do that with more data and place it in the corresponding sheets and new data going to the next row?

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Please ask the full question at first instead of in stages. We could have resolved this immediately instead of over 3 or 4 attempts.

    Does your data have header rows?

  9. #9
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Here's an earlier post with a similar request

    http://www.excelforum.com/excel-prog...n-keyword.html

  10. #10
    Registered User
    Join Date
    11-21-2008
    Location
    Toronto Ontario
    Posts
    5
    Sorry about that. I get that data each week and it needs to take the data and put it into the worksheets. so if you ran the macro again it would take the data and copy it to their own sheets.

    Thanks again for your help.
    Attached Files Attached Files

  11. #11
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    You haven't adjusted the code correctly to ork with the right sheet or columns

    Option Explicit
    '---------------------------------------------------------------------------------------
    ' Module    : Module1
    ' DateTime  : 24/09/2006 22:48
    ' Author    : Roy Cox (royUK)
    ' Website   :  more examples
    ' Purpose   :  Create a sheet for each unique name in data
    ' Disclaimer; This code is offered as is with no guarantees. You may use it in your
    '             projects but please leave this header intact.
    '---------------------------------------------------------------------------------------
    
    Sub ExtractToSheets()
        Dim ws     As Worksheet
        Dim wsNew  As Worksheet
        Dim rData  As Range
        Dim rCl    As Range
        Dim sNm    As String
        Set ws = Sheets("Sheet2")
    
        'extract a list of unique names
        'first clear existing list
        With ws
            Set rData = .Range(.Cells(1, 1), .Cells(.Rows.Count, 11).End(xlUp))
            .Columns(.Columns.Count).Clear
            .Range(.Cells(1, 1), .Cells(.Rows.Count, 1).End(xlUp)).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=.Cells(1, .Columns.Count), Unique:=True
    
            For Each rCl In .Range(.Cells(1, .Columns.Count), .Cells(.Rows.Count, .Columns.Count).End(xlUp))
                sNm = rCl.Text
                'add new sheet (only if required-NB uses UDF)
                If WksExists(sNm) Then
                    'so clear contents
                    Sheets(sNm).Cells.Clear
                Else
                    'new sheet required
                    Set wsNew = Sheets.Add
                    wsNew.Move After:=Worksheets(Worksheets.Count)    'move to end
                    wsNew.Name = sNm
                End If
                'AutoFilter & copy to relevant sheet
                rData.AutoFilter Field:=1, Criteria1:=sNm
                rData.Copy Destination:=Worksheets(sNm).Cells(1, 1)
            Next rCl
       End With
        ws.Columns(Columns.Count).ClearContents        'remove temporary list
        rData.AutoFilter        'switch off AutoFilter
    End Sub
    
    Function WksExists(wksName As String) As Boolean
        On Error Resume Next
        WksExists = CBool(Len(Worksheets(wksName).Name) > 0)
    End Function

+ 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