Help with an Excel VBA Autofilter copy paste syntax problem anyone?

Davavo

Board Regular
Joined
Aug 3, 2019
Messages
82
Hi folks,

I am a bit syuck on the auto-filter syntax.

can anyone tell me how to change this so that I am not copying and pasting the whole row, but only copying range "A" to "L" to usdrws and pasting into range "B" to "M", (same rows as below).

Code:
ws.AutoFilter.Range.Offset(1).EntireRow.Copy Trgtws.Range("L" & Rows.Count).End(xlUp).Offset(1, -11)

It does work as it is, but I want to paste to column B, not A.

full code ...
Code:
With Workbooks.Open(myFile)  
        Set wb = Workbooks.Open(FileName:=myFile, ReadOnly:=False)
  
             For Each ws In wb.Worksheets
                ws.Columns("k").Hidden = False
                Usdrws = ws.Range("L" & Rows.Count).End(xlUp).Row
                ws.Range("A1:L" & Usdrws).AutoFilter Field:=12, Criteria1:="*zhan*", Operator:=xlOr, Criteria2:="*revenue*"
                'Worksheets("Sheet1").Range("A1").AutoFilter Field:=2, Criteria1:="Printer", Operator:=xlOr, Criteria2:="Projector"
                  ws.AutoFilter.Range.Offset(1).EntireRow.Copy Trgtws.Range("L" & Rows.Count).End(xlUp).Offset(1, -11)
                  ws.AutoFilterMode = False
              Next ws
            
  wb.Close False
  
End With

thanks for any help
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Try this

Code:
    For Each ws In wb.Worksheets
      ws.Columns("k").Hidden = False
      Usdrws = ws.Range("L" & Rows.Count).End(xlUp).Row
      ws.Range("A1:L" & Usdrws).AutoFilter Field:=12, Criteria1:="*zhan*", Operator:=xlOr, Criteria2:="*revenue*"
      'Worksheets("Sheet1").Range("A1").AutoFilter Field:=2, Criteria1:="Printer", Operator:=xlOr, Criteria2:="Projector"
      ws.AutoFilter.Range.Offset(1)[COLOR=#0000ff].Range("A2:L" & Usdrws)[/COLOR].Copy Trgtws.Range("L" & Rows.Count).End(xlUp).Offset(1, -11)
      ws.AutoFilterMode = False
    Next ws
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,149
Members
453,021
Latest member
Justyna P

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