filter cell value and copy/paste

asyamonique

Well-known Member
Joined
Jan 29, 2008
Messages
1,286
Office Version
  1. 2013
Platform
  1. Windows
Code:
Dim LR As Long, i As Long
LR = Range("AM" & Rows.Count).End(xlUp).Row
For i = 1 To LR
With Range("AM" & i)
If .Value = Range("A1").Value Then
.Offset(, 1).Resize(, 26).Copy
Range("D" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
End If
End With
Next i

Good Day,
How can we improve the above code to increase the range targets like in same time i will get the A1:A10 values instead of getting only one cell value?
Many Thanks
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
This uses the .AutoFilter method to filter column AM for each filter value in A2:A11. It then copies the filtered results to column D.
Note: AutoFilter presumes the top row is a header row. The code copies filtered results in columns AN:BN starting from from row 2.

Code:
    Dim LR As Long
    Dim rngFilterVals As Range, c As Range, rngResult As Range, NextCell As Range
    
    Set rngFilterVals = Range("A2:A11")
    
    LR = Range("AM" & Rows.Count).End(xlUp).Row
    
    Application.ScreenUpdating = False
    
    For Each c In rngFilterVals
        If Not Range("AM1:AM" & LR).Find(c.Value, , xlValues, xlWhole, , , False) Is Nothing Then
            Set NextCell = Range("D" & Rows.Count).End(xlUp).Offset(1)
            Range("AM1:AM" & LR).AutoFilter Field:=1, Criteria1:=c.Value
            Range("AN2:BN" & LR).SpecialCells(xlCellTypeVisible).Copy
            NextCell.PasteSpecial Paste:=xlPasteValues
            Range("AM1:AM" & LR).AutoFilter
        End If
    Next c

    ActiveSheet.AutoFilterMode = False
    Application.CutCopyMode = True
    Application.ScreenUpdating = True
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,600
Messages
6,179,836
Members
452,947
Latest member
Gerry_F

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