Need help with Copy and Paste after autofilter

UPSDuder

New Member
Joined
Feb 14, 2019
Messages
10
After I apply an autofilter to get to the data I am wanting to work with I need to make Column AA equal to Column X. Is there a way to paste into visible cells of AA or a way to set the cell in AA = X? Being that it is a moving target I am not sure how to declare this range.

Current code: That cannot be used on multiple selections

Dim xlBook As Workbook
Dim xlSheet As Worksheet
Dim LastRow As Long
Dim LastRow2 As Long

Set xlBook = ActiveWorkbook
Set xlSheet = xlBook.Sheets("dspExcelExport")
If xlSheet.AutoFilterMode Then
xlSheet.AutoFilter.ShowAllData




'filter for AM times and update AA to reflect 12
xlSheet.Range("A:AA").AutoFilter Field:=21, Criteria1:="*AM*"

xlSheet.Range("X2:X" & LastRow).SpecialCells(xlCellTypeVisible).Copy _
Destination:=xlSheet.Range("AA2").SpecialCells(xlCellTypeVisible)
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
this my attempt at trying a loop to copy each visible cell in column X and paste it into the respective row in column AA, it runs.... but nothing is copied over.


xlSheet.Range("A:AA").AutoFilter Field:=21, Criteria1:="*AM*"
Dim MyRange As Range
Dim myCell As Range
Dim visRow As Long

visRow = xlSheet.Range("X" & Rows.Count).End(xlUp).Row

Set MyRange = xlSheet.Range("X2:X" & visRow).SpecialCells(xlCellTypeVisible)
For Each myCell In MyRange
ActiveCell.Copy
ActiveCell.Offset(3, 0).PasteSpecial xlPasteValues
Next
 
Upvote 0
How about
Code:
Set myrange = xlSheet.Range("X2:X" & visRow).SpecialCells(xlCellTypeVisible)
For Each MyCell In myrange
   MyCell.Offset(, 3).Value = MyCell.Value
Next
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,340
Members
452,638
Latest member
Oluwabukunmi

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