lenticular
New Member
- Joined
- Sep 10, 2014
- Messages
- 3
Hi there! I just started learning VBA yesterday and could use some help....
I have two workbooks: one "sept" workbook with a sheet of data per day for 7 stations (for a total of 30 sheets), and one "Stn" workbook with 7 sheets, one per station, with each sheet containing a large list of dates.
I want to take data for a given day (1 sheet) for all 7 stations from "sept", and paste it into the corresponding cells for that day in the "stn", into each respective station's sheet.
So far, I've made a code that can do this if I tell it exactly which cell corresponds to the date that I am pasting from. What I'm trying to do is make it match or find the date itself (dates are in yyyy-mm-dd format for both sheets) based on a cell in each sheet in "sept" that has the date, and paste the data into the neighbouring cell of the corresponding date in the stn workbook. And then I want to try and make it loop so it can do that for each of the 30 days....
Here is what I have so far:
I have two workbooks: one "sept" workbook with a sheet of data per day for 7 stations (for a total of 30 sheets), and one "Stn" workbook with 7 sheets, one per station, with each sheet containing a large list of dates.
I want to take data for a given day (1 sheet) for all 7 stations from "sept", and paste it into the corresponding cells for that day in the "stn", into each respective station's sheet.
So far, I've made a code that can do this if I tell it exactly which cell corresponds to the date that I am pasting from. What I'm trying to do is make it match or find the date itself (dates are in yyyy-mm-dd format for both sheets) based on a cell in each sheet in "sept" that has the date, and paste the data into the neighbouring cell of the corresponding date in the stn workbook. And then I want to try and make it loop so it can do that for each of the 30 days....
Here is what I have so far:
Code:
Sub LoopSept()
Windows("sept.xlsm").Activate
Dim st As Worksheet 'This is me trying to simplify things for the loop
For Each st In Sheets 'This is me trying to make it loop, work in progress
Windows("sept.xlsm").Activate
st.Range("A1:R183").ClearFormats 'When I've gotten it to work, instead of st, I had ActiveSheet
st.Range("B49:O51").Copy 'This is data from Sept that I want to paste into the first station's sheet in stn
Windows("Stn.xlsx").Activate
Worksheets("CYVR").Activate
ActiveSheet.Range("C5").Activate 'C5 corresponds to the date where I wanted it to paste, however I manually determined that, this is the part I want to get it to find the corresponding date. In the future, it would use range("B30") of sept to match to dates in column B of the stn sheet
ActiveSheet.Paste
Windows("sept.xlsm").Activate
st.Range("B71:O73").Copy 'This is data from sept that I want to paste into the 2nd station's sheet in stn
Windows("Stn.xlsx").Activate
Worksheets("CYYJ").Activate
ActiveSheet.Range("C5").Activate
ActiveSheet.Paste
Windows("sept.xlsm").Activate
ActiveSheet.Range("B93:O95").Copy
Windows("Stn.xlsx").Activate
Worksheets("CYXX").Activate
ActiveSheet.Range("C5").Activate
ActiveSheet.Paste
Windows("sept.xlsm").Activate
ActiveSheet.Range("B115:O117").Copy
Windows("Stn.xlsx").Activate
Worksheets("CWSK").Activate
ActiveSheet.Range("C5").Activate
ActiveSheet.Paste
Windows("sept.xlsm").Activate
ActiveSheet.Range("B137:O139").Copy
Windows("Stn.xlsx").Activate
Worksheets("CVOC").Activate
ActiveSheet.Range("C5").Activate
ActiveSheet.Paste
Windows("sept.xlsm").Activate
ActiveSheet.Range("B159:O161").Copy
Windows("Stn.xlsx").Activate
Worksheets("CYQQ").Activate
ActiveSheet.Range("C5").Activate
ActiveSheet.Paste
Windows("sept.xlsm").Activate
ActiveSheet.Range("B181:O183").Copy
Windows("Stn.xlsx").Activate
Worksheets("CWQC").Activate
ActiveSheet.Range("C5").Activate
ActiveSheet.Paste
Application.CutCopyMode = False
Next rs 'this is again me trying to loop....still a work in progress
End Sub