VBA Copy Question

O177812

Board Regular
Joined
Apr 16, 2015
Messages
82
Office Version
  1. 365
  2. 2021
HI I have data on a sheet (SHEET1) and I want to copy SOME of the data on a different sheet (SHEET2)

I am looking for VBA Code that will search Sheet1 in Column AO and if a cell contains a 0 then it will copy the coresponding value in Column A onto a list that starts in cell A2 on Sheet2.

Help is Appreciated!
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Try either (please note you must have headers in Sheet1)

Code:
Sub xsx2()
   With Sheets("Sheet1").Range("A1:AO" & Sheets("Sheet1").Range("AO" & Rows.Count).End(xlUp).Row)
        .AutoFilter Field:=41, Criteria1:="0"
        
        On Error Resume Next
    .Columns(1).Offset(1).Resize(.Rows.Count - 1).SpecialCells(12).Copy _
    Sheets("Sheet2").Range("A2")
        On Error GoTo 0
        .AutoFilter
    
    End With
End Sub

or if you are actually after the next blank row in Sheet2

Code:
Sub xsx2()
   With Sheets("Sheet1").Range("A1:AO" & Sheets("Sheet1").Range("AO" & Rows.Count).End(xlUp).Row)
        .AutoFilter Field:=41, Criteria1:="0"
        
        On Error Resume Next
    .Columns(1).Offset(1).Resize(.Rows.Count - 1).SpecialCells(12).Copy _
    Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1)
        On Error GoTo 0
        .AutoFilter
    
    End With
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,392
Messages
6,119,254
Members
448,879
Latest member
oksanana

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