there are a few threads related to conditional copy but none are addressing the issue I have.
Have a master sheet , Would like to copy specific column values ( along with the cell formating) to another sheet in the same workbook if there is a "X" in a specific column.
there are multiple columns with X to be copied to mutiple worksheets
Sample file attached
For example Would like to copy from Master sheet to a sheet "Ent App" columns Number and Title based on the "X" in the column Ent App.Would like the formating of the cells to be the same as in the master sheet after copying.
Same for all other columns in the worsheet.
this is the first time with excel macros....Any help appreciated.
Hi Anra
Try this codeLet me know of issues.Option Explicit Sub Macro1() Dim LR As Long Dim ws As Worksheet Dim Col As String Application.ScreenUpdating = False For Each ws In ActiveWorkbook.Worksheets If Not ws.Name = "Master" Then If ws.Name = "Ent App" Then Col = "C" ElseIf ws.Name = "Ent infr" Then Col = "D" ElseIf ws.Name = "Ent Arch" Then Col = "E" ElseIf ws.Name = "Ent PMO" Then Col = "F" End If With Sheets("Master") LR = .Range("A" & .Rows.Count).End(xlUp).Row .AutoFilterMode = False .Range(Col & "1:" & Col & LR).AutoFilter Field:=1, Criteria1:="X" .Range("A1:B" & LR).SpecialCells(xlVisible).Copy .AutoFilterMode = False End With Sheets(ws.Name).Range("A1").PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False Sheets(ws.Name).Range("A1").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False End If Next ws Application.ScreenUpdating = True End Sub
John
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
Thanks so much..just ran on the sample data and works perfectly..I will try it out on the real data and will let you know. Thanks again
Hi Anra
Yes please. Let me know how it goes.
John
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
Hi John - It works great on the real data!! Thank you!!
I'm embedding each worksheet on to a ppt and could you pl let me know how to add to this script -
when a new sheet is created with filtered data it automatically updates the sheet ( as it does now)
& also creates a new file and updates the same data.
So each filter will have 1 sheet + 1new file
Example : From master sheet we have created "Ent App" sheet (happening now with filtered contents) in addition to this create a new file and add a sheet "Ent App" with the same filtered content.
Is this possible? Any help on this will be great...thanks!
Hi Anra
A couple of things. I've no idea what this isSecondly, if I understand you correctly, you wish to filter the data for "Ent App" to it's worksheet as the code does now. Then you wish to create a new workbook called "Some Thing" that will have a worksheet in it called "Ent App". This new "Ent App" worksheet will contain the same data as the original copy of "Ent App". Is my understanding correct?a ppt
John
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
Yes that is correct and ppt - was power point..sorry
Hi Anra
I think this code does as you requestedPlease note there are two procedures here and they should both go in the same module. Also note that I've changed the previous code slightly so you'll need to replace it also. The code is in the attached.Option Explicit Dim ws As Worksheet Sub Macro1() Dim LR As Long Dim Col As String Application.ScreenUpdating = False For Each ws In ActiveWorkbook.Worksheets If Not ws.Name = "Master" Then If ws.Name = "Ent App" Then Col = "C" ElseIf ws.Name = "Ent infr" Then Col = "D" ElseIf ws.Name = "Ent Arch" Then Col = "E" ElseIf ws.Name = "Ent PMO" Then Col = "F" End If With Sheets("Master") LR = .Range("A" & .Rows.Count).End(xlUp).Row .AutoFilterMode = False .Range(Col & "1:" & Col & LR).AutoFilter Field:=1, Criteria1:="X" .Range("A1:B" & LR).SpecialCells(xlVisible).Copy .AutoFilterMode = False End With Sheets(ws.Name).Range("A1").PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False Sheets(ws.Name).Range("A1").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False Call AddBook End If Next ws Application.ScreenUpdating = True End Sub Sub AddBook() Dim bk As Workbook Dim bk1 As Workbook Set bk = ThisWorkbook Set bk1 = Workbooks.Add() Application.DisplayAlerts = False bk1.SaveAs bk.Path & "\" & ws.Name & ".xls", FileFormat:=xlExcel8 ActiveSheet.Name = ws.Name bk.Worksheets(ws.Name).Cells.Copy bk1.Worksheets(ws.Name).Range("A1").PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False bk1.Worksheets(ws.Name).Range("A1").PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _ False, Transpose:=False Application.DisplayAlerts = True bk1.Close savechanges:=True 'bk.Activate End Sub
Let me know of issues.
John
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
Many Thanks John..tried it out with my actual data and it works great!!
Some Files created are large with many rows..would it be possible to add some condition
to say that when the row count in the newly created file exceeds say 50 (testing purposes) to create
a new file which has header row + rows that are greater than 50...
No changes to the tab sheets created by the macro..just the files should add the confition
Hi Anra
Glad it works for you.
Regarding thisAre you saying that if in a new file to be created, the Row Count is going to be more that 50, then create a second file and split the file into two files? If this is the case, submit a file that exceeds row count of 50 to give me a file to test against.Some Files created are large with many rows..would it be possible to add some condition
to say that when the row count in the newly created file exceeds say 50 (testing purposes) to create
a new file which has header row + rows that are greater than 50...
John
Last edited by jaslake; 07-30-2010 at 07:19 PM.
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
Hi John - thats correct. Attached are 2 file. Sample file with apx 150 rows ( master file ) and another file Ent App.xls both for test... thanks a bunch
Hi Anra
I'm traveling this weekend and next week. I'll have some but not much spare time. I'll look at this possibility for you. What would the second Ent App file be called...perhaps Ent App 1?
John
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
yes..that should be fine. if there are 140 rows for example..would like it to create 3 files Ent App1( 50 rows ) Ent App2 ( 50 rows) Ent App3 ( 40 rows). thank you!
Hi John - would appreciate any help on the rowcount section. Have no macro experience...I tried doing it myself and it started to mess with the existing code...please help
Thank you so much for all the help so far, I ran the macro on the final data set and it ran perfectly... Thank you!!
Hi Anra
Sorry I haven't gotten back to you. I've been working with my son, daughter-in-law and two grandsons with their new home. Been working 10 hour days and haven't had the clarity of mind to work on your solution.
Going home on Thursday and will address your issue this weekend.
John
John
If you have issues with Code I've provided, I appreciate your feedback.
In the event Code provided resolves your issue, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.
If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks