Copy to Another

billandrew

Well-known Member
Joined
Mar 9, 2014
Messages
743
Looking to copy 6 columns which are not adjacent to each other, if cell value = a specific criteria to another Workbook starting in Column K.
The column row height could change when received.

The order on the copied "Master" sheet is
- Column B
- Column C
- Column I
- Column J
- Column E
- Column F


Hope this provides the necessary info.
 
How about this mod to mumps code
Code:
Sub CopyCols()
    Application.ScreenUpdating = False
    Dim bottomA As Long
    bottomA = Range("A" & Rows.Count).End(xlUp).Row
    Range("A1:J" & bottomA).AutoFilter Field:=3, Criteria1:="=Central", Operator:=xlOr, Criteria2:="=North"
    Intersect(Rows("2:" & bottomA), Range("B:B,C:C,I:I,J:J")).Copy Workbooks("Daily Report.xlsx").Sheets("Sheet1").Cells(Rows.Count, "K").End(xlUp).Offset(1, 0)
    Intersect(Rows("2:" & bottomA), Range("E:F")).Copy Workbooks("Daily Report.xlsx").Sheets("Sheet1").Cells(Rows.Count, "O").End(xlUp).Offset(1, 0)
    If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Awesome - Works Great!

Can I bother now, probably heard this before.:)

Like to Filter & Copy "West" Criteria to workbook "Daily Report" Sheet2 & "East" Criteria to workbook "Daily Report" Sheet3. Same order of columns as above. Is it simply copying the supplied code and changing the Criteria and Worksheets copied to?
 
Upvote 0
How about
Code:
Sub CopyCols()
   Dim bottomA As Long
   Dim Ary As Variant
   Dim i As Long
   
   Ary = Array("North|Central", "Sheet1", "West", "sheet2", "East", "Sheet3")
   Application.ScreenUpdating = False
   With ActiveSheet
      bottomA = .Range("A" & Rows.Count).End(xlUp).Row
      If .AutoFilterMode Then .AutoFilterMode = False
      For i = 0 To UBound(Ary) Step 2
         Range("A1:J1").AutoFilter 3, Split(Ary(i), "|"), xlFilterValues
         Intersect(Rows("2:" & bottomA), Range("B:B,C:C,I:I,J:J")).Copy Workbooks("Daily Report.xlsx").Sheets(Ary(i + 1)).Cells(Rows.Count, "K").End(xlUp).Offset(1, 0)
         Intersect(Rows("2:" & bottomA), Range("E:F")).Copy Workbooks("Daily Report.xlsx").Sheets(Ary(i + 1)).Cells(Rows.Count, "O").End(xlUp).Offset(1, 0)
      Next i
      .AutoFilterMode = False
   End With
End Sub
 
Upvote 0
Thank You

There is one problem, if there is no specific criteria then the entire data is copied.

Ex. Column C = "East" and there are no cell values with East.
 
Upvote 0
Try
Code:
Sub CopyCols()
   Dim bottomA As Long
   Dim Ary As Variant
   Dim i As Long
   
   Ary = Array("North|Central", "Sheet1", "West", "sheet2", "East", "Sheet3")
   Application.ScreenUpdating = False
   With ActiveSheet
      bottomA = .Range("A" & Rows.Count).End(xlUp).Row
      If .AutoFilterMode Then .AutoFilterMode = False
      For i = 0 To UBound(Ary) Step 2
         Range("A1:J1").AutoFilter 3, Split(Ary(i), "|"), xlFilterValues
         Intersect(Rows("2:" & bottomA), Range("B:B,C:C,I:I,J:J")).SpecialCells(xlVisible).Copy Workbooks("Daily Report.xlsx").Sheets(Ary(i + 1)).Cells(Rows.Count, "K").End(xlUp).Offset(1, 0)
         Intersect(Rows("2:" & bottomA), Range("E:F")).SpecialCells(xlVisible).Copy Workbooks("Daily Report.xlsx").Sheets(Ary(i + 1)).Cells(Rows.Count, "O").End(xlUp).Offset(1, 0)
      Next i
      .AutoFilterMode = False
   End With
End Sub
 
Upvote 0
How about
Code:
Sub CopyCols()
   Dim bottomA As Long
   Dim Ary As Variant
   Dim i As Long
   
   Ary = Array("North|Central", "Sheet1", "West", "sheet2", "East", "Sheet3")
   Application.ScreenUpdating = False
   With ActiveSheet
      bottomA = .Range("A" & Rows.Count).End(xlUp).Row
      If .AutoFilterMode Then .AutoFilterMode = False
      For i = 0 To UBound(Ary) Step 2
         Range("A1:J1").AutoFilter 3, Split(Ary(i), "|"), xlFilterValues
         On Error Resume Next
         Intersect(Rows("2:" & bottomA), Range("B:B,C:C,I:I,J:J")).SpecialCells(xlVisible).Copy Workbooks("Daily Report.xlsx").Sheets(Ary(i + 1)).Cells(Rows.Count, "K").End(xlUp).Offset(1, 0)
         Intersect(Rows("2:" & bottomA), Range("E:F")).SpecialCells(xlVisible).Copy Workbooks("Daily Report.xlsx").Sheets(Ary(i + 1)).Cells(Rows.Count, "O").End(xlUp).Offset(1, 0)
         On Error GoTo 0
      Next i
      .AutoFilterMode = False
   End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,333
Members
452,636
Latest member
laura12345

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