Hi All,
I want to automatically copy data from an old Excel Workbook into a new workbook based on criteria using VBA. I already found a good example of this here:
Copy Data to Another Excel WorkBook Based on Criteria Using VBA | Excel VBA Training Videos
However, this example puts the VBA code into the old Excel workbook. I can't modify the old so I need help "flipping" this code to put it in the new workbook and have it work.
Here's the code in the example:
Thanks for your help.
-Nick
I want to automatically copy data from an old Excel Workbook into a new workbook based on criteria using VBA. I already found a good example of this here:
Copy Data to Another Excel WorkBook Based on Criteria Using VBA | Excel VBA Training Videos
However, this example puts the VBA code into the old Excel workbook. I can't modify the old so I need help "flipping" this code to put it in the new workbook and have it work.
Here's the code in the example:
Code:
[COLOR=#000000]Sub mySales()
Dim LastRow As Integer, i As Integer, erow As Integer[/COLOR]
[COLOR=#000000]LastRow = ActiveSheet.Range(“A” & Rows.Count).End(xlUp).Row[/COLOR]
[COLOR=#000000]
For i = 2 To LastRow[/COLOR]
[COLOR=#000000]
If Cells(i, 1) = Date And Cells(i, 2) = “Sales” Then
Range(Cells(i, 1), Cells(i, 7)).Select
Selection.Copy[/COLOR]
[COLOR=#000000]
Workbooks.Open Filename:=”C:\Users\takyar\Documents\salesmaster-new.xlsx”
Worksheets(“Sheet1″).Select
erow = ActiveSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row[/COLOR]
[COLOR=#000000]
ActiveSheet.Cells(erow, 1).Select
ActiveSheet.Paste
ActiveWorkbook.Save
ActiveWorkbook.Close
Application.CutCopyMode = False
End If[/COLOR]
[COLOR=#000000]
Next i
[/COLOR]
[COLOR=#000000]End Sub[/COLOR]
Thanks for your help.
-Nick