Boulder2008
New Member
- Joined
- Jun 29, 2018
- Messages
- 4
Hello,
I am currently trying to write a macro that will take a shifts daily output and place it in a daily log that will be progressively kept through the year.
The workbook submitted by my Supervisors has the date, a shift drop down with selections (1ST, 2ND, 3RD) and four different products. Once they fill this out and click on the "Submit" button I would like the macro to copy the relevant data into the correct Shift and Date location in my second workbook. I am not sure how to ensure that the data is copied into the correct shift and date since every day it will need to be indexed to a new spot and we dont always run on the weekend and we dont always run all 3 shifts a day.
I messed around with the "Private Sub Worksheet_Change(ByVal Target As Range) for the drop down list, but had no luck in getting that version of code to work. I appreciate any assistance I can get regarding this issue.
My current code is:
[TABLE="width: 421"]
<colgroup><col span="2"><col><col><col span="2"></colgroup><tbody>[TR]
[TD] Sub TransferData()
Dim WkBk As Workbook
Dim SrcWkBk As Workbook
Set SrcWkBk = ThisWorkbook
Set WkBk = Workbooks.Open(Filename:="INSERT FILE NAME.xlsm")
'Copy Total Number of Parts per Line
SrcWkBk.Sheets("Hourly Counts").Range("P4").Copy
WkBk.Worksheets("Sheet1").Range("C2").PasteSpecial Paste:=xlPasteValues
SrcWkBk.Sheets("Hourly Counts").Range("P6").Copy
WkBk.Worksheets("Sheet1").Range("C5").PasteSpecial Paste:=xlPasteValues
WkBk.SaveAs ("C:\INSERT FILE LOCATION" & Format(Date, "MM-DD-YYYY") & ".xlsm")
'Clear Clipboard
Application.CutCopyMode = False
End Sub
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]My log file looks like:
[TABLE="width: 0"]
<tbody>[TR]
[TD]
[/TD]
[TD]
Date
Shift
[/TD]
[TD]6/27/2018
[/TD]
[TD]6/28/2018
[/TD]
[TD]6/29/2018
[/TD]
[TD]6/30/2018
[/TD]
[/TR]
[TR]
[TD]Product 1
[/TD]
[TD]3
[/TD]
[TD][/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[/TR]
[TR]
[TD]Product 2
[/TD]
[TD]3[/TD]
[TD][/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD][/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[/TR]
[TR]
[TD]Product 3
[/TD]
[TD]3
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[/TR]
[TR]
[TD]Product 4
[/TD]
[TD]
3
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][/TD]
[TD] [/TD]
[TD] [/TD]
[/TR]
</tbody>[/TABLE]
I am currently trying to write a macro that will take a shifts daily output and place it in a daily log that will be progressively kept through the year.
The workbook submitted by my Supervisors has the date, a shift drop down with selections (1ST, 2ND, 3RD) and four different products. Once they fill this out and click on the "Submit" button I would like the macro to copy the relevant data into the correct Shift and Date location in my second workbook. I am not sure how to ensure that the data is copied into the correct shift and date since every day it will need to be indexed to a new spot and we dont always run on the weekend and we dont always run all 3 shifts a day.
I messed around with the "Private Sub Worksheet_Change(ByVal Target As Range) for the drop down list, but had no luck in getting that version of code to work. I appreciate any assistance I can get regarding this issue.
My current code is:
[TABLE="width: 421"]
<colgroup><col span="2"><col><col><col span="2"></colgroup><tbody>[TR]
[TD] Sub TransferData()
Dim WkBk As Workbook
Dim SrcWkBk As Workbook
Set SrcWkBk = ThisWorkbook
Set WkBk = Workbooks.Open(Filename:="INSERT FILE NAME.xlsm")
'Copy Total Number of Parts per Line
SrcWkBk.Sheets("Hourly Counts").Range("P4").Copy
WkBk.Worksheets("Sheet1").Range("C2").PasteSpecial Paste:=xlPasteValues
SrcWkBk.Sheets("Hourly Counts").Range("P6").Copy
WkBk.Worksheets("Sheet1").Range("C5").PasteSpecial Paste:=xlPasteValues
WkBk.SaveAs ("C:\INSERT FILE LOCATION" & Format(Date, "MM-DD-YYYY") & ".xlsm")
'Clear Clipboard
Application.CutCopyMode = False
End Sub
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]My log file looks like:
[TABLE="width: 0"]
<tbody>[TR]
[TD]
[/TD]
[TD]
Date
Shift
[/TD]
[TD]6/27/2018
[/TD]
[TD]6/28/2018
[/TD]
[TD]6/29/2018
[/TD]
[TD]6/30/2018
[/TD]
[/TR]
[TR]
[TD]Product 1
[/TD]
[TD]3
[/TD]
[TD][/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[/TR]
[TR]
[TD]2
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[/TR]
[TR]
[TD]Product 2
[/TD]
[TD]3[/TD]
[TD][/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[/TR]
[TR]
[TD]1
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD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