Do While Help required

gaurav23

New Member
Joined
Apr 16, 2011
Messages
8
Hi,

I have 5 sheets in a file viz. Data,Class,A,B,C,D,E.

I have written a macro to extract the class column from Data and remove the duplicates and list them in Class sheet.

Now i want to write a macro which will autofilter the data based on cell value and paste them to the respective sheet.

Here is the code i have written.

Dim a as integer
Dim b as variant

Sheets("Class").Select
Range("A2").Select
a = Range("A2").Row

DO while activecell <> empty

b = Range("A" & a).Value
Sheets("Data").Select

Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.AutoFilter

ActiveSheet.Range("A1:" & lcol & lrow).AutoFilter Field:=8, Criteria1:=""" & b & """

Range("A1").Select
Range(Selection, Selection.End(xlToRight)).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy

Sheets("""& b & """).Select

ActiveSheet.Paste

Sheets("Class").Select

Range("A" & a).Select

ActiveCell.Offset(1, 0).Select

a = a + 1

Loop

But it is generating a run time error at Auto filter but the criteria i want is to select automatically based on the cell values.

Please help me with this.

Thanks & Regards,
Gaurav.
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

Forum statistics

Threads
1,224,516
Messages
6,179,231
Members
452,898
Latest member
Capolavoro009

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