You are on page 1of 3

Sub mySales()

Dim LastRow As Integer, i As Integer, erow As Integer

LastRow = ActiveSheet.Range(“A” & Rows.Count).End(xlUp).Row

For i = 2 To LastRow

If Cells(i, 1) = Date And Cells(i, 2) = “Sales” Then

Range(Cells(i, 1), Cells(i, 7)).Select

Selection.Copy

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

ActiveSheet.Cells(erow, 1).Select

ActiveSheet.Paste

ActiveWorkbook.Save

ActiveWorkbook.Close

Application.CutCopyMode = False

End If

Next i

End Sub
Code:

Sub Foo()

Dim vFile As Variant

Dim wbCopyTo As Workbook

Dim wsCopyTo As Worksheet

Dim wbCopyFrom As Workbook

Dim wsCopyFrom As Worksheet

Set wbCopyTo = ActiveWorkbook

Set wsCopyTo = ActiveSheet

'-------------------------------------------------------------

'Open file with data to be copied

vFile = Application.GetOpenFilename("Excel Files (*.xl*)," & _

"*.xl*", 1, "Select Excel File", "Open", False)

'If Cancel then Exit

If TypeName(vFile) = "Boolean" Then

Exit Sub

Else

Set wbCopyFrom = Workbooks.Open(vFile)

Set wsCopyFrom = wbCopyFrom.Worksheets(1)

End If
'--------------------------------------------------------------

'Copy Range

wsCopyFrom.Range("B6:E12").Copy

wsCopyTo.Range("B5").PasteSpecial Paste:=xlPasteValues, _

Operation:=xlNone, SkipBlanks:=False, Transpose:=False

'Close file that was opened

wbCopyFrom.Close SaveChanges:=False

End Sub

You might also like