ziad alsayed
Well-known Member
- Joined
- Jul 17, 2010
- Messages
- 665
dear all
the below Code is working fine, i just need to reduce it
what it simply does that it removes data from onw workbook to another.
each workbook has 6 sheets and each sheet has data for 12 month
hope you can assist in reducing the code.
i am sure it can be reduded, but i am not good in using array yet
below is the code
the below Code is working fine, i just need to reduce it
what it simply does that it removes data from onw workbook to another.
each workbook has 6 sheets and each sheet has data for 12 month
hope you can assist in reducing the code.
i am sure it can be reduded, but i am not good in using array yet
below is the code
Code:
Sub MoveSalesByMonth()
Dim wb As Workbook ' this workbook is "Sales Statistics 2007_2011"
Dim wbn As Workbook
Set wb = ActiveWorkbook
Set wsph = wb.Worksheets("PH")
wsph.Select
ChDir "D:\"
Workbooks.Open Filename:="D:\Nigeria Files\Sales Statistics Amount\Sales Statistics Amount 2011.xlsm", UpdateLinks:=0
Sheets("PHC2011 $").Select
'copy january
Cells(50, 4).Copy
wsph.Cells(8, 2).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy Feb
Cells(50, 5).Copy
wsph.Cells(8, 3).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy March
Cells(50, 6).Copy
wsph.Cells(8, 4).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy April
Cells(50, 7).Copy
wsph.Cells(8, 5).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy may
Cells(50, 8).Copy
wsph.Cells(8, 6).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy June
Cells(50, 9).Copy
wsph.Cells(8, 7).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy July
Cells(50, 10).Copy
wsph.Cells(8, 8).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy August
Cells(50, 11).Copy
wsph.Cells(8, 9).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'copy September
Cells(50, 12).Copy
wsph.Cells(8, 10).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy October
Cells(50, 13).Copy
wsph.Cells(8, 11).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy November
Cells(50, 14).Copy
wsph.Cells(8, 12).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy december
Cells(50, 15).Copy
wsph.Cells(8, 13).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
ActiveWindow.Close
'Apapa Branch
Set wsApapa = wb.Worksheets("Apapa")
wsApapa.Select
ChDir "D:\"
Workbooks.Open Filename:="D:\Nigeria Files\Sales Statistics Amount\Sales Statistics Amount 2011.xlsm", UpdateLinks:=0
Sheets("Apapa2011 $").Select
'copy january
Cells(50, 4).Copy
wsApapa.Cells(8, 2).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy Feb
Cells(50, 5).Copy
wsApapa.Cells(8, 3).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy March
Cells(50, 6).Copy
wsApapa.Cells(8, 4).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy April
Cells(50, 7).Copy
wsApapa.Cells(8, 5).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy may
Cells(50, 8).Copy
wsApapa.Cells(8, 6).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy June
Cells(50, 9).Copy
wsApapa.Cells(8, 7).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy July
Cells(50, 10).Copy
wsApapa.Cells(8, 8).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy August
Cells(50, 11).Copy
wsApapa.Cells(8, 9).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'copy September
Cells(50, 12).Copy
wsApapa.Cells(8, 10).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy October
Cells(50, 13).Copy
wsApapa.Cells(8, 11).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy November
Cells(50, 14).Copy
wsApapa.Cells(8, 12).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy december
Cells(50, 15).Copy
wsApapa.Cells(8, 13).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
ActiveWindow.Close
'VI Branch
Set wsVI = wb.Worksheets("VI")
wsVI.Select
ChDir "D:\"
Workbooks.Open Filename:="D:\Nigeria Files\Sales Statistics Amount\Sales Statistics Amount 2011.xlsm", UpdateLinks:=0
Sheets("VI2011 $").Select
'copy january
Cells(50, 4).Copy
wsVI.Cells(8, 2).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy Feb
Cells(50, 5).Copy
wsVI.Cells(8, 3).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy March
Cells(50, 6).Copy
wsVI.Cells(8, 4).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy April
Cells(50, 7).Copy
wsVI.Cells(8, 5).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy may
Cells(50, 8).Copy
wsVI.Cells(8, 6).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy June
Cells(50, 9).Copy
wsVI.Cells(8, 7).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy July
Cells(50, 10).Copy
wsVI.Cells(8, 8).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy August
Cells(50, 11).Copy
wsVI.Cells(8, 9).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'copy September
Cells(50, 12).Copy
wsVI.Cells(8, 10).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy October
Cells(50, 13).Copy
wsVI.Cells(8, 11).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy November
Cells(50, 14).Copy
wsVI.Cells(8, 12).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy december
Cells(50, 15).Copy
wsVI.Cells(8, 13).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
ActiveWindow.Close
'Kano Branch
Set wsKano = wb.Worksheets("Kano")
wsKano.Select
ChDir "D:\"
Workbooks.Open Filename:="D:\Nigeria Files\Sales Statistics Amount\Sales Statistics Amount 2011.xlsm", UpdateLinks:=0
Sheets("Kano2011 $").Select
'copy january
Cells(50, 4).Copy
wsKano.Cells(8, 2).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy Feb
Cells(50, 5).Copy
wsKano.Cells(8, 3).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy March
Cells(50, 6).Copy
wsKano.Cells(8, 4).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy April
Cells(50, 7).Copy
wsKano.Cells(8, 5).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy may
Cells(50, 8).Copy
wsKano.Cells(8, 6).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy June
Cells(50, 9).Copy
wsKano.Cells(8, 7).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy July
Cells(50, 10).Copy
wsKano.Cells(8, 8).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy August
Cells(50, 11).Copy
wsKano.Cells(8, 9).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'copy September
Cells(50, 12).Copy
wsKano.Cells(8, 10).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy October
Cells(50, 13).Copy
wsKano.Cells(8, 11).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy November
Cells(50, 14).Copy
wsKano.Cells(8, 12).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy december
Cells(50, 15).Copy
wsKano.Cells(8, 13).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
ActiveWindow.Close
'Abuja Branch
Set wsAbuja = wb.Worksheets("Abuja")
wsAbuja.Select
ChDir "D:\"
Workbooks.Open Filename:="D:\Nigeria Files\Sales Statistics Amount\Sales Statistics Amount 2011.xlsm", UpdateLinks:=0
Sheets("Abuja2011 $").Select
'copy january
Cells(50, 4).Copy
wsAbuja.Cells(8, 2).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy Feb
Cells(50, 5).Copy
wsAbuja.Cells(8, 3).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy March
Cells(50, 6).Copy
wsAbuja.Cells(8, 4).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy April
Cells(50, 7).Copy
wsAbuja.Cells(8, 5).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy may
Cells(50, 8).Copy
wsAbuja.Cells(8, 6).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy June
Cells(50, 9).Copy
wsAbuja.Cells(8, 7).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy July
Cells(50, 10).Copy
wsAbuja.Cells(8, 8).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy August
Cells(50, 11).Copy
wsAbuja.Cells(8, 9).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'copy September
Cells(50, 12).Copy
wsAbuja.Cells(8, 10).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy October
Cells(50, 13).Copy
wsAbuja.Cells(8, 11).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy November
Cells(50, 14).Copy
wsAbuja.Cells(8, 12).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy december
Cells(50, 15).Copy
wsAbuja.Cells(8, 13).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
ActiveWindow.Close
'Abuja Branch
Set wsIkeja = wb.Worksheets("Ikeja")
wsIkeja.Select
ChDir "D:\"
Workbooks.Open Filename:="D:\Nigeria Files\Sales Statistics Amount\Sales Statistics Amount 2011.xlsm", UpdateLinks:=0
Sheets("Ikeja2011 $").Select
'copy january
Cells(50, 4).Copy
wsIkeja.Cells(8, 2).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy Feb
Cells(50, 5).Copy
wsIkeja.Cells(8, 3).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy March
Cells(50, 6).Copy
wsIkeja.Cells(8, 4).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy April
Cells(50, 7).Copy
wsIkeja.Cells(8, 5).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy may
Cells(50, 8).Copy
wsIkeja.Cells(8, 6).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy June
Cells(50, 9).Copy
wsIkeja.Cells(8, 7).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy July
Cells(50, 10).Copy
wsIkeja.Cells(8, 8).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy August
Cells(50, 11).Copy
wsIkeja.Cells(8, 9).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'copy September
Cells(50, 12).Copy
wsIkeja.Cells(8, 10).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy October
Cells(50, 13).Copy
wsIkeja.Cells(8, 11).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy November
Cells(50, 14).Copy
wsIkeja.Cells(8, 12).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
'Copy december
Cells(50, 15).Copy
wsIkeja.Cells(8, 13).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
Application.CutCopyMode = False
ActiveWindow.Close
End Sub