+ Reply to Thread
Results 1 to 7 of 7

Distributing data into varying tabs VBA

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-19-2013
    Location
    Las Vegas, NV
    MS-Off Ver
    Office 365 2016
    Posts
    214

    Distributing data into varying tabs VBA

    Hello all,

    Been a little while, but am back with a VBA question. I copied a generic VBA code (https://yodalearning.com/tutorials/e...to-split-data/) to distribute information from the attached sample file's "TestTab" using the 7th column's field "AssetClass" to new tabs per each "AssetClass" type.

    I tried to modify the codee for my file as best I could but am getting stuck at the point where it filters and attempts to create a new sheet
    rData.Copy Destination:=Worksheets(assetclass).Cells(1, 1)
    Below is the full code

    Sub ExtractToSheets()
        Dim ws          As Worksheet
        Dim wsNew       As Worksheet
        Dim rData       As Range
        Dim rfl         As Range
        Dim assetclass  As String
        Set ws = ThisWorkbook.Sheets("testtab")
    
        With ws
            Set rData = .Range(.Cells(1, 1), .Cells(.Rows.Count, 7).End(xlUp))
            .Columns(.Columns.Count).Clear
            .Range(.Cells(2, 7), .Cells(.Rows.Count, 7).End(xlUp)).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=.Cells(1, .Columns.Count), Unique:=True
        
        'Calls Excel Advanced Filter
        
            For Each rfl In .Range(.Cells(1, .Columns.Count), .Cells(.Rows.Count, .Columns.Count).End(xlUp))
                assetclass = rfl.Text
        
                rData.AutoFilter Field:=7, Criteria1:=assetclass
                rData.Copy Destination:=Worksheets(assetclass).Cells(1, 1)
            Next rfl
        End With
        ws.Columns(Columns.Count).ClearContents
        rData.AutoFilter
    End Sub
    Also on the included sample file are three green tabs showing the expected results. Thank you for any help.
    Kondukt
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try this ‼


    As a beginner starter :

    PHP Code: 
    Sub Demo()
            
    Dim R&, S$
            
    Application.ScreenUpdating False
        With Sheet1
                
    .[A1].CurrentRegion.Columns(7).AdvancedFilter xlFilterCopy, , .[K1], True
            
    For 2 To .[K1].CurrentRegion.Rows.Count
                S 
    = .Cells(R11).Value2
               
    .[K2].Value2 S
                
    If Evaluate("ISREF('" "'!A1)") = False Then Sheets.Add(, Sheets(Sheets.Count)).Name S
               
    .[A1].CurrentRegion.AdvancedFilter xlFilterCopy, .[K1:K2], Sheets(S).[A1].CurrentRegion.Rows(1)
            
    Next
               
    .[K1].CurrentRegion.Clear
        End With
            Application
    .ScreenUpdating True
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 05-09-2019 at 06:50 PM.

  3. #3
    Forum Contributor
    Join Date
    01-19-2013
    Location
    Las Vegas, NV
    MS-Off Ver
    Office 365 2016
    Posts
    214

    Re: Distributing data into varying tabs VBA

    Hey Marc,

    Thank you for the reply and help, but when I try this code instead it breaks at
    .[A1].CurrentRegion.Columns(7).AdvancedFilter xlFilterCopy, , .[K1], True
    asking to debug.

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Re: Distributing data into varying tabs VBA


    No issue on my side with your attachment …

  5. #5
    Forum Contributor
    Join Date
    01-19-2013
    Location
    Las Vegas, NV
    MS-Off Ver
    Office 365 2016
    Posts
    214

    Re: Distributing data into varying tabs VBA

    My fault, had a different file's module open. It works. Thank you good sir.

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Thumbs up


    Thanks for the rep' !

  7. #7
    Forum Contributor
    Join Date
    01-19-2013
    Location
    Las Vegas, NV
    MS-Off Ver
    Office 365 2016
    Posts
    214

    Re: Distributing data into varying tabs VBA

    Hey Marc, sorry to rebump this thread but I was wondering if you would be willing to update the VBA on this for me? I tried modifying it to my final file but haven't been able to. Also, I added some formatting requests if it isn't too much trouble. I have attached a sample file that has all the same structures as my final file with an expected results tab for an example labeled "AssetClass FinalTab to build"

    PS. I Amazon Prime'd a VBA book last night.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Formulas on Mutliple Tabs With Varying Rows of Data
    By spyldbrat in forum Excel General
    Replies: 2
    Last Post: 08-02-2017, 05:51 PM
  2. Need help with a VBA code for distributing data
    By cspeid03 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-22-2016, 01:40 AM
  3. [SOLVED] Formula to correlate varying data in one column to varying data in another column
    By Chris_SS in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-09-2014, 07:36 AM
  4. Distributing values or data with a group???
    By FifiNguyen in forum Excel General
    Replies: 0
    Last Post: 03-01-2014, 03:46 AM
  5. [SOLVED] Distributing Data from an expanding worksheet list and appending to various tabs in the sa
    By Cdot in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-24-2013, 09:06 PM
  6. Pulling large amounts of data from varying tabs
    By bjvick in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-14-2010, 05:24 PM
  7. Distributing Data
    By Milnet in forum Excel General
    Replies: 6
    Last Post: 08-10-2009, 02:55 AM

Tags for this Thread

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