remove columns and rows - create two workbooks - Macro

I need a macro which creates two new workbooks - The workbooks should be as follows

Workbook 1

1. Remove all columns apart from those highlighted yellow
2. Remove all rows containing the value "Branches" in column G (note this column will be removed as it is not yellow).
3. Remove all cell formatting
4. Rename the worksheet in the new workbook Members
5. Ensure that the two other worksheets in the original workbook are removed (Principals & News Flash).

Workbook 2

Repeat the same process for the second workbook but this time remove rows containing "Members" and rename the worksheet "Branches"

Note: I have only highlighted the columns yellow to demonstrate the required columns. Therefore do not create a conditional rule around this formatting.

Note 2: The original workbook should be closed without saving any changes, the two new workbooks should remain open.

I have attached three workbooks, the original, and two to show an example of the results the macro should return.

Mike
memberDB.xlsm
Branches.xlsm
Members.xlsm
mikes6058Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
Option Explicit

Sub CreateWorkbooks()
Dim wbSource As Workbook
Dim wbNew As Workbook

Application.ScreenUpdating = False
Set wbSource = ThisWorkbook

Workbooks.Add
Set wbNew = ActiveWorkbook

wbSource.Sheets("Database").Copy Before:=wbNew.Sheets(1)

With ActiveSheet
    .Name = "Members"
    .UsedRange.Value = .UsedRange.Value
    .Columns("G:G").Select
    Selection.AutoFilter
    .Cells.AutoFilter Field:=1, Criteria1:="Branch"
    .AutoFilter.Range.Offset(1).Resize(.Rows.Count - 1).EntireRow.Delete
    .Cells.AutoFilter
    .Range("A:B,D:H,Q:R,V:Y,AA:AK,AM:DH").Delete
End With

Workbooks.Add
Set wbNew = ActiveWorkbook

wbSource.Sheets("Database").Copy Before:=wbNew.Sheets(1)

With ActiveSheet
    .Name = "Branches"
    .UsedRange.Value = .UsedRange.Value
    .Columns("G:G").Select
    Selection.AutoFilter
    .Cells.AutoFilter Field:=1, Criteria1:="Member"
    .AutoFilter.Range.Offset(1).Resize(.Rows.Count - 1).EntireRow.Delete
    .Cells.AutoFilter
    .Range("A:B,D:H,Q:R,V:Y,AA:AK,AM:DH").Delete
End With

End Sub

Open in new window

mikes6058Author Commented:
Hi Martin,

Thanks, just two things to alter.

1.Column AL should not be included. Apologies this was my mistake

2. All the formatting needs to be removed. i.e. fonts, cell highlighting, bolding etc.

Otherwise spot on

Mike
Martin LissOlder than dirtCommented:
Here you go. BTW if you used some tool to obfuscate the data on the sheet, can you tell me what it was?

Sub CreateWorkbooks()
Dim wbSource As Workbook
Dim wbNew As Workbook

Set wbSource = ThisWorkbook

Application.ScreenUpdating = False

Workbooks.Add
Set wbNew = ActiveWorkbook

wbSource.Sheets("Database").Copy Before:=wbNew.Sheets(1)

With ActiveSheet
    .Name = "Members"
    .UsedRange.Value = .UsedRange.Value
    .UsedRange.ClearFormats
    .Columns("G:G").Select
    Selection.AutoFilter
    .Cells.AutoFilter Field:=1, Criteria1:="Branch"
    .AutoFilter.Range.Offset(1).Resize(.Rows.Count - 1).EntireRow.Delete
    .Cells.AutoFilter
    .Range("A:B,D:H,Q:R,V:Y,AA:AL,AM:DH").Delete
End With

Workbooks.Add
Set wbNew = ActiveWorkbook

wbSource.Sheets("Database").Copy Before:=wbNew.Sheets(1)

With ActiveSheet
    .Name = "Branches"
    .UsedRange.Value = .UsedRange.Value
    .UsedRange.ClearFormats
    .Columns("G:G").Select
    Selection.AutoFilter
    .Cells.AutoFilter Field:=1, Criteria1:="Member"
    .AutoFilter.Range.Offset(1).Resize(.Rows.Count - 1).EntireRow.Delete
    .Cells.AutoFilter
    .Range("A:B,D:H,Q:R,V:Y,AA:AL,AM:DH").Delete
End With

End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mikes6058Author Commented:
Kutools
Martin LissOlder than dirtCommented:
I'm glad I was able to help and thank you for the information.

In my profile you'll find links to some articles I've written that may interest you.
Marty - MVP 2009 to 2015, Experts-Exchange Top Expert Visual Basic Classic 2012 to 2014
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.