+ Reply to Thread
Results 1 to 7 of 7

Macro question - Copying rows into worksheets based on criteria of a specific column

Hybrid View

jpsprack Macro question - Copying rows... 06-26-2012, 12:48 PM
arlu1201 Re: Macro question - Copying... 06-26-2012, 01:20 PM
jpsprack Re: Macro question - Copying... 06-26-2012, 01:28 PM
MarvinP Re: Macro question - Copying... 06-26-2012, 01:43 PM
jpsprack Re: Macro question - Copying... 06-26-2012, 01:55 PM
arlu1201 Re: Macro question - Copying... 06-27-2012, 06:39 AM
jpsprack Re: Macro question - Copying... 06-27-2012, 04:38 PM
  1. #1
    Registered User
    Join Date
    06-14-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    26

    Macro question - Copying rows into worksheets based on criteria of a specific column

    Ok while I am pretty proficient with the basics of Excel... and some advanced stuff. Macros so far I have not touched.

    I have a workbook with roughly 250-300 worksheets for specific accounts and programs.
    The first worksheet is a master list that will have as the columns - Account, Program, Revenue, Divisional Income, Net

    What I would love to be able to do is when I get my download for the data is to have a macro run and take each row and plop it into the proper worksheet based on the Program.
    Currently its done manually and takes a fair bit of time to do. I would like to automate as much as possible.

    So my question is.... Is this possible? and if so... how!

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Macro question - Copying rows into worksheets based on criteria of a specific column

    Yes its possible. Why dont you upload a sample file of your data?

    To Attach a File:

    1. Click on Go Advanced.
    2. In the frame Attach Files you will see the button Manage Attachments
    3. Click the button.
    4. A new window will open titled Manage Attachments - Excel Forum.
    5. Click the Browse... button to locate your file for uploading.
    6. This will open a new window File Upload.
    7. Once you have located the file to upload click the Open button. This window will close.
    8. You are now back in the Manage Attachments - Excel Forum window.
    9. Click the Upload button and wait until the file has uploaded.
    10. Close the window and then click Submit.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    06-14-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    26

    Re: Macro question - Copying rows into worksheets based on criteria of a specific column

    Yup I sure can. See attached file
    Attached Files Attached Files

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,268

    Re: Macro question - Copying rows into worksheets based on criteria of a specific column

    Hi jpsprack,

    I've used your data and created a pivot table using it. See the attached and open it.
    Pivot Tables have a feature called "Drill Down" where you can create new sheets of data showing specific records.

    If you open the attached and double click on a number in the pivot table, it will create a new sheet of what you want.
    Example - Double click on the 1045 next to the AAA. You will then have a new sheet of only AAA acount data.

    I hope this is easier than writing VBA. (You can rename the new sheet names to the Account if you need). Why have multiple sheets if they are easy to create like this?
    Attached Files Attached Files
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  5. #5
    Registered User
    Join Date
    06-14-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    26

    Re: Macro question - Copying rows into worksheets based on criteria of a specific column

    I will have to see if I can apply this to the workbook. The only issue I see is that the pivot table is creating new sheets(Sheet 1, Sheet 2, etc) instead of populating the current sheets.
    Even if there is no data for some programs the sheets still need to be in the workbook. If a pivot table is able to be directed to populate the current sheets that would be much better than trying to write VBA I would think.

    I do appreciate the response. That first approach still may work for some other files I need to do for my work.

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Macro question - Copying rows into worksheets based on criteria of a specific column

    Try this code
    Option Explicit
    
    Sub transfer_sheets()
    Dim i As Long, lrow As Long
    Dim sname As String
    
    With Worksheets("MAIN")
        lrow = .Range("A" & .Rows.Count).End(xlUp).Row
        For i = 2 To lrow
            sname = .Range("B" & i).Value
            If Not Evaluate("ISREF('" & sname & "'!A1)") Then
                Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = sname
                .Rows("1:1").Copy Worksheets(sname).Range("A1")
            End If
            .Rows(i).Copy Worksheets(sname).Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
        Next i
    End With
    End Sub
    Copy the Excel VBA code
    Select the workbook in which you want to store the Excel VBA code
    Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
    Choose Insert | Module
    Where the cursor is flashing, choose Edit | Paste

    To run the Excel VBA code:
    Choose View | Macros
    Select a macro in the list, and click the Run button.

  7. #7
    Registered User
    Join Date
    06-14-2012
    Location
    Canada
    MS-Off Ver
    Excel 2010
    Posts
    26

    Re: Macro question - Copying rows into worksheets based on criteria of a specific column

    That worked great!! thanks... I hope I can apply that to the full workbook but for the test example it worked perfectly.

    Thanks!

+ 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