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

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Forum statistics

Threads
1,223,574
Messages
6,173,144
Members
452,501
Latest member
musallam

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