Transfer lines to tab that matches column D

surkdidat

Well-known Member
Joined
Oct 1, 2011
Messages
582
Office Version
  1. 365
HI

Hope someone can help me.... I am guessing its some sort of INDIRECT, but not sure how exactly I go about it

I have the below example table. This is in a tab called "MAIN"

Also, I have tabs called "Team_A" "Team_B" "Team_C" etc.

These names are in Column D on the MAIN tab

What I need to do is have something that will extract all the lines to the correct tab.

(On my real data there are currently around 200 lines and 7 tabs, but more data will be added as I go along, so not really practical to filter and cut and paste as I want the data to be in real time, and not have anything missed.

Thanks

Column AColumn BColumn CColumn D (TAB NAMES)
AdamSmithBlueTEAM_A
PeterJonesBlueTEAM_A
StevenHayesGreenTEAM_C
PeterCaddickOrangeTEAM_A
AndrewBellOrangeTEAM_B
TimLovejoyTEAM_D
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Hello Surkdidat,

Try the following VBA code placed into a standard module and assigned to a button on your "MAIN" sheet:-

VBA Code:
Sub Test()

        Dim ar As Variant, wsM As Worksheet, wsT As Worksheet
        Set wsM = Sheets("MAIN")
        ar = Array("TEAM_A", "TEAM_B", "TEAM_C", "TEAM_D")

Application.ScreenUpdating = False

        For i = 0 To UBound(ar)
                Set wsT = Sheets(ar(i))
                With wsM.[A1].CurrentRegion
                        .AutoFilter 4, ar(i)
                        .Offset(1).EntireRow.Copy wsT.Range("A" & Rows.Count).End(3)(2)
                        .AutoFilter
                End With
        Next i

Application.ScreenUpdating = True

End Sub

I hope that this helps.

Cheerio,
vcoolio.
 
Upvote 0
Apologies, I should have said the first row of data starts in cell A4
 
Last edited by a moderator:
Upvote 0
Is row 4 headings with data starting in row 5?
 
Upvote 0
Here you go Surkdidat:-

VBA Code:
Sub Test()

        Dim ar As Variant, wsM As Worksheet, wsT As Worksheet
        Set wsM = Sheets("MAIN")
        ar = Array("TEAM_A", "TEAM_B", "TEAM_C", "TEAM_D") '---->Add sheet names as required.

Application.ScreenUpdating = False

        For i = 0 To UBound(ar)
                Set wsT = Sheets(ar(i))
                With wsM.Range("D3", wsM.Range("D" & wsM.Rows.Count).End(xlUp))
                        .AutoFilter 1, ar(i)
                        .Offset(1).EntireRow.Copy wsT.Range("A" & Rows.Count).End(3)(2)
                        .AutoFilter
                End With
        Next i

Application.ScreenUpdating = True

End Sub

Cheerio,
vcoolio.
 
Upvote 0

Forum statistics

Threads
1,215,151
Messages
6,123,316
Members
449,094
Latest member
Chestertim

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top