+ Reply to Thread
Results 1 to 15 of 15

Code from tigeravatar ,Copying data from one sheet and copying it

Hybrid View

  1. #1
    Registered User
    Join Date
    11-30-2011
    Location
    Arizona
    MS-Off Ver
    Excel 2003
    Posts
    27

    Post Code from tigeravatar ,Copying data from one sheet and copying it

    I want to look at column C and i have 3 values in there and dictate where i pull the data into the 3 different Templates. ( apples goes to template 1, Oranges goes to template 2, and Coconuts goes to template 3 )
    tigeravatar got me this far. any help will be appreciated.
    Daniel


    Sub wigiPL()
        
        Dim NameCell As Range
        For Each NameCell In Sheets("! Names").Range("B1", Sheets("! Names").Cells(Rows.Count, "B").End(xlUp))
            Sheets("! Temp").Copy After:=Sheets(Sheets.Count)
            With Sheets("! Temp (2)")
                .Name = NameCell.Text
                .Range("C2").Value = NameCell.Text
                .Range("C3").Value = NameCell.Offset(, 2).Value
                .Range("E1").Value = NameCell.Offset(, 1).Value
                .Range("E2").Value = NameCell.Offset(, 3).Value
                .Range("E3").Value = NameCell.Offset(, 7).Value
                .Range("E4").Value = NameCell.Offset(, -1).Value
                .Range("C4").Value = NameCell.Offset(, 6).Value
                .Range("C5").Value = NameCell.Offset(, 5).Value
                .Range("E5").Value = NameCell.Offset(, 8).Value
                    
            End With
        Next NameCell
        Application.CutCopyMode = False
        
    End Sub

  2. #2
    Forum Contributor
    Join Date
    06-23-2010
    Location
    Iowa, United States
    MS-Off Ver
    Excel 2007
    Posts
    145

    Re: Code from tigeravatar ,Copying data from one sheet and copying it

    Someone may be able to help without one, but if you can upload a workbook, I believe I can figure this out.
    A VBA novice, excited to learn!

  3. #3
    Registered User
    Join Date
    11-30-2011
    Location
    Arizona
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Code from tigeravatar ,Copying data from one sheet and copying it

    Template1 will be peach, template2 willbe oranges, template3 will be Apples, Template4 will be Grapes. I want to use the primary data ( Fruit ) to go to a differnet Tempalte. The macro i use will pull the data that i need , I just want all the peach to go to peach Tempalte and Apples to go to Apple template and so on.
    [ATTACH]198283 [/ATTACH]


    Sub wigiPL()
        
        Dim NameCell As Range
        For Each NameCell In Sheets("Names").Range("B1", Sheets("Names").Cells(Rows.Count, "B").End(xlUp))
            Sheets("Template1").Copy after:=Sheets(Sheets.Count)
            With Sheets("Template1")
                .Name = NameCell.Text
                .Range("C2").Value = NameCell.Text
                .Range("C3").Value = NameCell.Offset(, 2).Value
                .Range("E1").Value = NameCell.Offset(, 1).Value
                .Range("E2").Value = NameCell.Offset(, 3).Value
                .Range("E3").Value = NameCell.Offset(, 7).Value
                .Range("E4").Value = NameCell.Offset(, -1).Value
                .Range("C4").Value = NameCell.Offset(, 6).Value
                .Range("C5").Value = NameCell.Offset(, 5).Value
                .Range("E5").Value = NameCell.Offset(, 8).Value
                    
            End With
        Next NameCell
        Application.CutCopyMode = False
        
    End Sub
    Attached Files Attached Files
    Last edited by JBeaucaire; 12-07-2012 at 01:11 PM. Reason: added missing [/CODE] tag

  4. #4
    Registered User
    Join Date
    11-30-2011
    Location
    Arizona
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Code from tigeravatar ,Copying data from one sheet and copying it


  5. #5
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Code from tigeravatar ,Copying data from one sheet and copying it

    DanielRay,

    Your posted example workbook has the fruits in column E when your original post said to look in column C. Also, the posted example workbook doesn't have a sheet named Template1, only Template2 through 4, and a sheet named 'Solo' with some prefilled information. Basically, it's confusing.

    Do you want to split the data in the 'Names' sheet based on the entry in column E (in this case, the fruit)? Does each row get its own sheet, or should all "Oranges" go into a single sheet based on 'Template2'? What data in the row goes where in the template?
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  6. #6
    Registered User
    Join Date
    11-30-2011
    Location
    Arizona
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Code from tigeravatar ,Copying data from one sheet and copying it

    Hey tigeravatar

    I uploaded the file now. When you look at the sheet where the data is going to be pulled from you will see the fruit column. I want to search by the fruit first and put the that info into the appropriate sheet ( Apples, Peach, Oranges, Grapes )
    the left over data that will be pulled will be the same on all the other sheets. I would like to also have it create the new worksheet with the name of the person. For example if it has a grapes use the grape template but great the new sheet with the name. I hope i explained it clearly. Let me know if I didnt.

    ForumQuest.xlsx

  7. #7
    Registered User
    Join Date
    11-30-2011
    Location
    Arizona
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Code from tigeravatar ,Copying data from one sheet and copying it

    The name is col B

  8. #8
    Registered User
    Join Date
    11-30-2011
    Location
    Arizona
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Code from tigeravatar ,Copying data from one sheet and copying it

    oh and The fruit will go in E2 on all the templates

  9. #9
    Registered User
    Join Date
    11-30-2011
    Location
    Arizona
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Code from tigeravatar ,Copying data from one sheet and copying it

    This what i have so far, Doesnt work but on the right direction.

    Sub Fruit()
        
        Dim NameCell As Range
        For Each NameCell In Sheets("! Names").Range("B1", Sheets("! Names").Cells(Rows.Count, "B").End(xlUp))
            Sheets("! Temp").Copy after:=Sheets(Sheets.Count)
            With Sheets("! Temp (2)")
                .Name = NameCell.Text
                .Range("C2").Value = NameCell.Text
                .Range("C3").Value = NameCell.Offset(, 2).Value
                .Range("E2").Value = NameCell.Offset(, 1).Value
                .Range("E3").Value = NameCell.Offset(, 3).Value
                .Range("E4").Value = NameCell.Offset(, 7).Value
                .Range("E5").Value = NameCell.Offset(, -1).Value
                .Range("C4").Value = NameCell.Offset(, 6).Value
                .Range("C5").Value = NameCell.Offset(, 5).Value
                .Range("E6").Value = NameCell.Offset(, 8).Value
                    
            End With
        Next NameCell
        Application.CutCopyMode = False
        
    End Sub

  10. #10
    Registered User
    Join Date
    11-30-2011
    Location
    Arizona
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Code from tigeravatar ,Copying data from one sheet and copying it

    Just realized we wouldnt need the sheet named Template1. Do you agree?

  11. #11
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Code from tigeravatar ,Copying data from one sheet and copying it

    DanielRay,

    Because each "template" sheet seems to be 100% identical, I don't see why you need 4 different ones instead of just one sheet named 'Template'. Here is a code that you could use for that. I wasn't sure what cells in the row go where on the template, so I only filled in a few:
    Sub tgr()
        
        Dim ws As Worksheet
        Dim NameCell As Range
        
        For Each NameCell In Sheets("Names").Range("B1", Sheets("Names").Cells(Rows.Count, "B").End(xlUp)).Cells
            Set ws = Sheets.Add(After:=Sheets(Sheets.Count))
            Sheets("Template").UsedRange.Copy
            With ws
                .Name = NameCell.Text
                .Range("A1").PasteSpecial xlPasteAll
                .Range("A1").PasteSpecial xlPasteColumnWidths
                .Range("C2").Value = NameCell.Text
                .Range("C3").Value = NameCell.Offset(, 2).Value
                .Range("E2").Value = NameCell.Offset(, 3).Value
            End With
            Set ws = Nothing
        Next NameCell
        
    End Sub

  12. #12
    Registered User
    Join Date
    11-30-2011
    Location
    Arizona
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Code from tigeravatar ,Copying data from one sheet and copying it

    I wil be adding a bottom part later. for example if the fruit is apples it will go to the apples template where it will have everything about apples( recipies , history of the Fruit, and so on ). the part i want to auto populate
    is just gonna be the info part. I may have 10 people wanting apples and 3 wanting Grapes. I will be wanting to create a new sheet according to the fruit tempalte but will have their last name,fist name as the new sheet name.

  13. #13
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Code from tigeravatar ,Copying data from one sheet and copying it

    In that case...
    Sub tgr()
        
        Dim ws As Worksheet
        Dim NameCell As Range
        
        For Each NameCell In Sheets("Names").Range("B1", Sheets("Names").Cells(Rows.Count, "B").End(xlUp)).Cells
            Set ws = Sheets.Add(After:=Sheets(Sheets.Count))
            Sheets(NameCell.Offset(, 3).Text).UsedRange.Copy
            With ws
                .Name = NameCell.Text
                .Range("A1").PasteSpecial xlPasteAll
                .Range("A1").PasteSpecial xlPasteColumnWidths
                .Range("C2").Value = NameCell.Text
                .Range("C3").Value = NameCell.Offset(, 2).Value
                .Range("E2").Value = NameCell.Offset(, 3).Value
            End With
            Set ws = Nothing
        Next NameCell
        
    End Sub

  14. #14
    Registered User
    Join Date
    11-30-2011
    Location
    Arizona
    MS-Off Ver
    Excel 2003
    Posts
    27

    Re: Code from tigeravatar ,Copying data from one sheet and copying it

    This is SOLVED ! Thanks tigeravatar!!!
    Last edited by DanielRay; 12-07-2012 at 03:13 PM. Reason: Wording

  15. #15
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Code from tigeravatar ,Copying data from one sheet and copying it

    This line:
    Sheets(NameCell.Offset(, 3).Text).UsedRange.Copy

+ 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