Macro help

John Davis

Well-known Member
Joined
Sep 11, 2007
Messages
3,457
Hello All:

I have the following:

Code:
Sub Test()
Dim x As Variant
Dim i As Long
Dim lr As Long

lr = Sheets("Sheet3").Cells(Rows.Count, 1).End(xlUp).Row
lr2 = Sheets("Sheet4").Cells(Rows.Count, 1).End(xlUp).Row + 1

With Sheets("Sheet3")

x = Array("WORD1", "WORD2", "WORD3", "WORD4")

For i = LBound(x) To UBound(x)

    .Range("A2:AA" & lr).AutoFilter Field:=6, Criteria1:=x
    .Range("A2:AA" & lr).EntireRow.SpecialCells(xlCellTypeVisible).Copy Sheets("Sheet4").Range("A" & lr2)
    .Range("A2:AA" & lr).AutoFilter

Next i

End With

End Sub

Can someone tell me why it does not work??
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Do you mean it's always [asting in the same row? You need to repeat this within your loop:

Code:
lr2 = Sheets("Sheet4").Cells(Rows.Count, 1).End(xlUp).Row + 1
 
Upvote 0
You haven't defined Lr2

lr2 = Sheets("Sheet4").Cells(Rows.Count, 1).End(xlUp).Row + 1
 
Upvote 0
Do you mean it's always [asting in the same row? You need to repeat this within your loop:

Code:
lr2 = Sheets("Sheet4").Cells(Rows.Count, 1).End(xlUp).Row + 1


Thanks for your reply Andy. I took your advice. But still having problems trying to get it too advance through the Array? The goal is to continue filtering copying and pasting too Sheet4 for each word in the Array. As is it only does the first word.
 
Upvote 0

Forum statistics

Threads
1,224,525
Messages
6,179,319
Members
452,905
Latest member
deadwings

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