AccountantHarry
New Member
- Joined
- Oct 13, 2019
- Messages
- 18
Hi everyone,
I am a VBA beginner, I have written a macro using codes from different threads here and watching youtube videos, it sounds easy to copy and paste data, however, there are some tricky requirements as the source workbook, the target worksheet and target range change based on the month of the year. For example in Sep:-
The source workbook is C:\Sales data\Sept 2019.xls. The name of the file will be Oct.xls next month. I have managed to make the file name changed based on a cell in a different workbook.
The source worksheet in this workbook is called "Actual", the name and the range "C4:C52", they don't change.
The target worksheet in this workbook is "Sep", but it will be "Oct" next month, so forth and so on.
The target range in this workbook is "J4:J52". but it will be "K4:K52" in Oct, so for and so on.
Application.DisplayAlerts = False[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
'Open Sales data workbook
Sheets("Macro set up").Select
Workbooks.Open(Filename:= _
Range("B6").Value _
, UpdateLinks:=0).RunAutoMacros Which:=xlAutoOpen[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
'Go to worksheets Actual, select data range and paste as value in current month's tab.
Worksheets("Actual").Range("C3:C52").Copy[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
' change the month and range each month, eg worksheets ("Oct").Range("K4")
Worksheets("Sep").Range("J4").PasteSpecial xlPasteValues[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
Application.CutCopyMode = False
End sub
[/FONT]
I change the macro codes for the target sheet name and range each month. I have tried to make them to base on a cell in the workbook I used for the file name, but without success. Any help and suggestions would be greatly appreciated.
Regards
I am a VBA beginner, I have written a macro using codes from different threads here and watching youtube videos, it sounds easy to copy and paste data, however, there are some tricky requirements as the source workbook, the target worksheet and target range change based on the month of the year. For example in Sep:-
The source workbook is C:\Sales data\Sept 2019.xls. The name of the file will be Oct.xls next month. I have managed to make the file name changed based on a cell in a different workbook.
The source worksheet in this workbook is called "Actual", the name and the range "C4:C52", they don't change.
The target worksheet in this workbook is "Sep", but it will be "Oct" next month, so forth and so on.
The target range in this workbook is "J4:J52". but it will be "K4:K52" in Oct, so for and so on.
I have the following codes:
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]Sub CopyPasge()
Application.DisplayAlerts = False[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
'Open Sales data workbook
Sheets("Macro set up").Select
Workbooks.Open(Filename:= _
Range("B6").Value _
, UpdateLinks:=0).RunAutoMacros Which:=xlAutoOpen[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
'Go to worksheets Actual, select data range and paste as value in current month's tab.
Worksheets("Actual").Range("C3:C52").Copy[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
' change the month and range each month, eg worksheets ("Oct").Range("K4")
Worksheets("Sep").Range("J4").PasteSpecial xlPasteValues[/FONT]
[FONT=Verdana,Arial,Tahoma,Calibri,Geneva,sans-serif]
Application.CutCopyMode = False
End sub
[/FONT]
I change the macro codes for the target sheet name and range each month. I have tried to make them to base on a cell in the workbook I used for the file name, but without success. Any help and suggestions would be greatly appreciated.
Regards