VBA Paste from autofilter with additional data

joeino

New Member
Joined
Oct 28, 2020
Messages
21
Office Version
  1. 365
  2. 2016
  3. 2013
Platform
  1. Windows
Hello,

I have simple code (see below) that requires some tweaking. So basically, what it does is, it filters the data from another worksheet and paste it to a different worksheet. What I want to do is when I run the macro, it will paste the data onto the destination sheet on columns A to Q and the word "test" on the next column (Col R). So if I have data from A2 to Q15. I will also have the word "test" from R2 to R15. Thank you in advance.



With wsA
.AutoFilterMode = False
.Range("AR:AR").AutoFilter
.Range("AR:AR").AutoFilter Field:=1, Criteria1:="No"
On Error Resume Next
wsA.Range("A2:Q" & lr).SpecialCells(xlCellTypeVisible).Copy wsB.Range("A" & Rows.Count).End(3)(2)
On Error GoTo 0
.AutoFilterMode = False
End With
 

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.
How about
VBA Code:
With wsA
.AutoFilterMode = False
.Range("AR:AR").AutoFilter
.Range("AR:AR").AutoFilter Field:=1, Criteria1:="No"
On Error Resume Next
   With WsB.Range("A" & Rows.Count).End(xlUp)
      wsA.Range("A2:Q" & lr).SpecialCells(xlCellTypeVisible).Copy .Offset(1)
      WsB.Range(.Offset(1, 17), WsB.Range("A" & Rows.Count).End(xlUp).Offset(, 17)).Value = "Test"
   End With
On Error GoTo 0
.AutoFilterMode = False
End With
 
Upvote 0
How about
VBA Code:
With wsA
.AutoFilterMode = False
.Range("AR:AR").AutoFilter
.Range("AR:AR").AutoFilter Field:=1, Criteria1:="No"
On Error Resume Next
   With WsB.Range("A" & Rows.Count).End(xlUp)
      wsA.Range("A2:Q" & lr).SpecialCells(xlCellTypeVisible).Copy .Offset(1)
      WsB.Range(.Offset(1, 17), WsB.Range("A" & Rows.Count).End(xlUp).Offset(, 17)).Value = "Test"
   End With
On Error GoTo 0
.AutoFilterMode = False
End With
Thank you Fluff! This is awesome!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,447
Messages
6,124,909
Members
449,195
Latest member
Stevenciu

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