Exporting rows to another workbook by matching criteria

dionysus_83

New Member
Joined
Feb 24, 2016
Messages
30
I have following code for exporting data to another workbook:

Code:
Public Sub EXPORTPLAN()

Dim Ans As Variant
Ans = MsgBox("Are you sure?", vbYesNo)
    Select Case Ans
    Case vbYes
    


Dim LastRow As Integer
Dim wSOURCE As Worksheet
Dim NextRow As Integer




Set wSOURCE = Sheets("ArchivePlan")


Workbooks.Open Filename:="C:\Users\Shiky\Desktop\Consumption 2016..xlsm"
Application.ScreenUpdating = False
    wSOURCE.Activate
    Cells.Select
    Selection.EntireColumn.Hidden = False
    Selection.EntireRow.Hidden = False
    Cells.AutoFilter
    
    wSOURCE.Activate
    wSOURCE.Range("W1").Select
    Selection.AutoFilter
    ActiveSheet.Range("$A$1:$w$100000").AutoFilter Field:=23, Criteria1:="NO"
    
    LastRow = wSOURCE.UsedRange.Rows.Count
    Range(Cells(2, 1), Cells(LastRow, 22)).Select
    Selection.Copy
    Workbooks("Consumption 2016..xlsm").Activate
    NextRow = Worksheets("Cutter").Cells(Worksheets("Cutter").Rows.Count, "A").End(xlUp).Row + 1
    Sheets("Cutter").Range("A" & NextRow).PasteSpecial xlPasteValues
    Workbooks("Cutter 2016.xlsm").Activate
      
    Worksheets("ControlPanel").Range("T1").Copy
    wSOURCE.Range(Cells(2, 23), Cells(LastRow - 2, 23)).PasteSpecial xlPasteValues
    
    
    wSOURCE.Range("P:W").EntireColumn.Hidden = True
    Cells.AutoFilter
    
    MsgBox ("Export completed!")
    
Application.ScreenUpdating = True
    
    
    Case vbNo
    GoTo Quit:
    End Select


Quit:
    
    
End Sub

It should filter data in one workbook that matches criteria NO in column W (or 23 column) and copy those rows to first blank row in another workbook. Afterwards it should mark all those transfered rows from first workbook wih YES instead of now in 23 column!

More or less this does what I need except:

1. If there is no rows matching criteria NO it copies all rows from first workbook
2. When it finish, it marks all cells in 23 column with YES not only transfered ones!

I tried with different methods of selecting those rows and marking them with YES (I cant do just substitute as sometime there will be something else than NO or YES!).
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

Forum statistics

Threads
1,217,091
Messages
6,134,509
Members
449,876
Latest member
Nurul96

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