VBA Conditional Copy and Paste

RoseG

New Member
Joined
Dec 14, 2010
Messages
14
Hey all

Could anyone please help with a little VBA?

I need something that will pull together contact details from several sheets in another workbook, if details have been left. i.e.

Copy:
Workbook "Data"
Sheets "Sheet1", "Sheet2" and "Sheet3"
Columns "H:O" and "AB"
IF the value in H is "Yes"

Paste:
Workbook "Book1"
Sheet "Sheet1"

As one of the columns is non-consecutive and I'm wanting to regularly update from several sheets, Advanced Filter doesn't seem like a good way to go.

Any advice?

Rose
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Hey all

Could anyone please help with a little VBA?

I need something that will pull together contact details from several sheets in another workbook, if details have been left. i.e.

Copy:
Workbook "Data"
Sheets "Sheet1", "Sheet2" and "Sheet3"
Columns "H:O" and "AB"
IF the value in H is "Yes"

Paste:
Workbook "Book1"
Sheet "Sheet1"

As one of the columns is non-consecutive and I'm wanting to regularly update from several sheets, Advanced Filter doesn't seem like a good way to go.

Any advice?

Rose

Untested. But perhaps?

Code:
Sub RoseG()
Dim lr As Long
Dim lr2 As Long
Dim x As Integer

With Workbooks("Data.xls")

For x = 1 To 3

Sheets(x).Select

lr = Workbooks("Data.xls").Sheets(x).Cells(Rows.Count, 1).End(xlUp).Row
lr2 = Workbooks("Book1.xls").Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row + 1
    
    Columns("H:H").AutoFilter
    Selection.AutoFilter Field:=1, Criteria1:="Yes"
    Range(Range("H" & lr), Range("O" & lr)).SpecialCells(xlCellTypeVisible).Copy Workbooks("Book1.xls").Sheets("Sheet1").Range("H" & lr2)
    Range("AB" & lr).Copy Workbooks("Book1.xls").Sheets("Sheet1").Range("AB" & lr2)
    Columns("H:H").AutoFilter
    
Next x
            
End With
      
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,613
Messages
6,179,898
Members
452,948
Latest member
Dupuhini

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