Copy Data based on region to relevant sheet name

howard

Well-known Member
Joined
Jun 26, 2006
Messages
6,561
Office Version
  1. 2021
Platform
  1. Windows
I have various sheets from sheet 5 onwards based on the unique region name in Col A on sheet1. Have a macro to create these sheet names


I have region names in Col A on sheet1 ("customers") from row 12 onwards and headings in row 11


I have a macro to copy all the data from row12 onwards based on the region to the relevant sheet name. for eg id "North" appears in Col A , then all the data pertaining to North to be copied to sheet "North" "East" to be copied to sheet "East" after the last row containing data on these sheets


See my code below


The code is clearing the data on sheet1. I cannot figure this out


It would be appreciated if someone could kindly amend my code

Code:
 Sub CopyDatatoRelevantSheets()
  Sheets(1).Select
  Dim ws As Worksheet
  Dim LR As Long
  LR = Cells(Rows.Count, "A").End(xlUp).Row
  For Each ws In Worksheets
    If ws.Name <> "Customers" And ws.Name <> "Report Name" And ws.Name <> "Purchases" And ws.Name <> "Email Addresses" Then
     
      Sheets("customers").Range("A11:U" & LR).Copy Destination:=ws.Range("A2")
      With ws.UsedRange
        .AutoFilter Field:=1, Criteria1:="<>" & ws.Name, Operator:=xlAnd, Criteria2:="<>"
       .Offset(1).EntireRow.Delete
        .AutoFilter
      End With
    End If
  Next ws
End Sub


Book1
ABCDEFG
1
2
3
4REGIONAL DATA
5
6GroupALL GROUPS
7BranchesALL BRANCHES
8Start Date01 Jan 2017
9End Date30 Apr 2018
10
11RegionClient CategoryTitleInitialsFirst NameLast NameID Number
12NorthBusinessMRR RRICHARDDavids07255839089
13NorthPRIVATEMRSAPeterSam02110152089
14EastPRIVATEMISSX ZDavidDaniel07305743088
15SouthPRIVATEMRVColinBack49483
16SouthPRIVATEMRSKSueSions11185745083
17GautBusinessMRO JPamDavids11185745083
18GautPRIVATEMRKDanielNoel09115092089
Customers
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Cross posted https://www.excelforum.com/excel-pr...aste-data-after-last-row-containing-data.html

While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules).
This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0

Forum statistics

Threads
1,214,515
Messages
6,119,973
Members
448,933
Latest member
Bluedbw

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