Copy to Range Keeping Dropdown lists

bthomas

Board Regular
Joined
Mar 4, 2008
Messages
139
Hi is there a way to copy data at each change to separate sheets while keeping your validation cells in tact?

I have the following code, but it drops my dropdown lists.

Code:
[FONT=Calibri]Sub DatatoTABS()[/FONT]
[COLOR=black][FONT=verdana]Dim wsAll As Worksheet[/FONT][/COLOR]
[FONT=verdana][COLOR=black]Dim wsCrit As Worksheet[/COLOR][/FONT]
[FONT=verdana][COLOR=black]Dim wsNew As Worksheet[/COLOR][/FONT]
[FONT=verdana][COLOR=black]Dim LastRow As Long[/COLOR][/FONT]
[FONT=verdana][COLOR=black]Dim LastRowCrit As Long[/COLOR][/FONT]
[FONT=verdana][COLOR=black]Dim I As Long[/COLOR][/FONT]
 
[FONT=verdana][COLOR=black]   Set wsAll = Worksheets("All") ' change All to the name of the worksheet the existing data is on[/COLOR][/FONT]
 
[FONT=verdana][COLOR=black]   LastRow = wsAll.Range("A" & Rows.Count).End(xlUp).Row[/COLOR][/FONT]
 
[FONT=verdana][COLOR=black]   Set wsCrit = Worksheets.Add[/COLOR][/FONT]
 
[FONT=verdana][COLOR=black]   ' column G has the criteria eg project ref[/COLOR][/FONT]
[FONT=verdana][COLOR=black]   wsAll.Range("G1:G" & LastRow).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=wsCrit.Range("A1"), Unique:=True[/COLOR][/FONT]
 
[FONT=verdana][COLOR=black]   LastRowCrit = wsCrit.Range("A" & Rows.Count).End(xlUp).Row[/COLOR][/FONT]
[FONT=verdana][COLOR=black]   For I = 2 To LastRowCrit[/COLOR][/FONT]
 
[FONT=verdana][COLOR=black]       Set wsNew = Worksheets.Add[/COLOR][/FONT]
[FONT=verdana][COLOR=black]       wsNew.Name = wsCrit.Range("A2")[/COLOR][/FONT]
[FONT=verdana][COLOR=black]       wsAll.Rows("1:" & LastRow).AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=wsCrit.Range("A1:A2"), _[/COLOR][/FONT]
[FONT=verdana][COLOR=black]        CopyToRange:=wsNew.Range("A1"), Unique:=False[/COLOR][/FONT]
[FONT=verdana][COLOR=black]       wsCrit.Rows(2).Delete[/COLOR][/FONT]
 
[FONT=verdana][COLOR=black]   Next I[/COLOR][/FONT]
 
[FONT=verdana][COLOR=black]   Application.DisplayAlerts = False[/COLOR][/FONT]
[FONT=verdana][COLOR=black]   wsCrit.Delete[/COLOR][/FONT]
[FONT=verdana][COLOR=black]   Application.DisplayAlerts = True[/COLOR][/FONT]
 
[FONT=verdana][COLOR=black]End Sub[/COLOR][/FONT]

Appreciate all of your help!
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,224,526
Messages
6,179,322
Members
452,906
Latest member
Belthazar

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