TaskMaster
Board Regular
- Joined
- Oct 15, 2020
- Messages
- 75
- Office Version
- 365
- 2016
- Platform
- Windows
Hi Everyone hoping that you can help me with the following query.
I have managed to use the following code to open another spreadsheet, that pulls data in from our database based on the parameters in cells C2:C5, and then copy the results into my current spreadsheet and then save the file as the product code, (at the minute im manually choosing the location until I fix the spreadsheet and then i'll chose the location). Our product code is in cell C2, C3:C5 will remain fixed. What I am hoping for is to use a loop to, repeat this process for a list of product codes in column P. Is this possible and if so could anyone point me in the right direction?
I have managed to use the following code to open another spreadsheet, that pulls data in from our database based on the parameters in cells C2:C5, and then copy the results into my current spreadsheet and then save the file as the product code, (at the minute im manually choosing the location until I fix the spreadsheet and then i'll chose the location). Our product code is in cell C2, C3:C5 will remain fixed. What I am hoping for is to use a loop to, repeat this process for a list of product codes in column P. Is this possible and if so could anyone point me in the right direction?
Entry Template1.xlsm | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | |||
1 | ||||||||||||||||||
2 | Enter Code | 304060 | Product Codes | |||||||||||||||
3 | Enter Month | 8 | 304060 | |||||||||||||||
4 | Enter Year | 2022 | 304061 | |||||||||||||||
5 | Enter Company | 1 | 319,214.99 | 570,977.12 | 319,214.99 | 570,977.12 | 304062 | |||||||||||
6 | 304063 | |||||||||||||||||
7 | PERIOD | BUS_DATE | CREATED | CREATED_BY | TYPE | JNLDESC | CURR_VAL | CURR_VAL | CURR_NET_VAL | GBP_VAL | GBP_VAL | GBP_NET_VAL | DESCRIPTION | 304064 | ||||
8 | AUG-22 | 31/08/2022 | 31/08/2022 | YKS Operations DO NO | 5 | Daily movements for 31-AUG-2022 | 12,773.17 | 12,773.17 | 12,773.17 | 12,773.17 | 122001 | 304065 | ||||||
9 | AUG-22 | 31/08/2022 | 31/08/2022 | YKS Operations DO NO | 5 | Daily movements for 31-AUG-2022 | 39,158.67 | 39,158.67 | 39,158.67 | 39,158.67 | 122003 | 304066 | ||||||
10 | AUG-22 | 31/08/2022 | 31/08/2022 | YKS Operations DO NO | 5 | Daily movements for 31-AUG-2022 | 43,436.63 | 43,436.63 | 43,436.63 | 43,436.63 | 122002 | 304067 | ||||||
11 | AUG-22 | 31/08/2022 | 31/08/2022 | YKS Operations DO NO | 5 | Daily movements for 31-AUG-2022 | 46,334.00 | 46,334.00 | 46,334.00 | 46,334.00 | 122000 | 304068 | ||||||
12 | AUG-22 | 31/08/2022 | 31/08/2022 | YKS Operations DO NO | 5 | Daily movements for 31-AUG-2022 | 47,052.57 | 47,052.57 | 47,052.57 | 47,052.57 | 121999 | 304069 | ||||||
13 | AUG-22 | 31/08/2022 | 31/08/2022 | YKS Operations DO NO | 5 | Daily movements for 31-AUG-2022 | 0.00 | 254,031.87 | -254,031.87 | 254,031.87 | -254,031.87 | 121539 | 304070 | |||||
14 | AUG-22 | 31/08/2022 | 31/08/2022 | YKS Operations DO NO | 5 | Daily movements for 31-AUG-2022 | 0.00 | 4,550.62 | -4,550.62 | 4,550.62 | -4,550.62 | 122001 | 304071 | |||||
15 | AUG-22 | 31/08/2022 | 31/08/2022 | YKS Operations DO NO | 5 | Daily movements for 31-AUG-2022 | 0.00 | 12,907.65 | -12,907.65 | 12,907.65 | -12,907.65 | 122003 | 304072 | |||||
16 | AUG-22 | 31/08/2022 | 31/08/2022 | YKS Operations DO NO | 5 | Daily movements for 31-AUG-2022 | 0.00 | 14,713.11 | -14,713.11 | 14,713.11 | -14,713.11 | 122002 | 304073 | |||||
17 | AUG-22 | 31/08/2022 | 31/08/2022 | YKS Operations DO NO | 5 | Daily movements for 31-AUG-2022 | 0.00 | 16,433.73 | -16,433.73 | 16,433.73 | -16,433.73 | 122000 | 304074 | |||||
18 | AUG-22 | 31/08/2022 | 31/08/2022 | YKS Operations DO NO | 5 | Daily movements for 31-AUG-2022 | 0.00 | 16,578.01 | -16,578.01 | 16,578.01 | -16,578.01 | 121999 | 304075 | |||||
19 | AUG-22 | 31/08/2022 | 31/08/2022 | YKS Operations DO NO | 5 | Daily movements for 31-AUG-2022 | 701,437.07 | 701,437.07 | 701,437.07 | 701,437.07 | 121539 | 304076 | ||||||
20 | 304077 | |||||||||||||||||
21 | 304078 | |||||||||||||||||
22 | 304079 | |||||||||||||||||
23 | 304080 | |||||||||||||||||
24 | 304081 | |||||||||||||||||
25 | 304082 | |||||||||||||||||
26 | 304083 | |||||||||||||||||
Summary |
Cell Formulas | ||
---|---|---|
Range | Formula | |
K5:L5,H5:I5 | H5 | =SUM(H8:H999) |
VBA Code:
Sub Refresh()
Dim Trans As String
Dim Entry As String
Dim Wbk As Workbook
Dim Folder As String
Dim FileName As String
Entry = "\\Documents\Entry Template1"
Trans = "\\Documents\TRAN Template.xlsm"
With Workbooks("Entry Template1").ActiveSheet
Set Wbk = Workbooks.Open(Trans, ReadOnly:=True)
Wbk.Sheets("ENQUIRY").Range("M1").Value = .Range("C4").Value
Wbk.Sheets("ENQUIRY").Range("M2").Value = .Range("C3").Value
Wbk.Sheets("ENQUIRY").Range("M4").Value = .Range("C5").Value
Wbk.Sheets("ENQUIRY").Range("M5").Value = .Range("C2").Value
End With
Application.Run ("'TRAN Template.xlsm'!TRANSACTION_QUERY")
With Workbooks("Entry Template1").ActiveSheet
LastRow = Wbk.Sheets("ENQUIRY").Cells(.Rows.Count, "J").End(xlUp).Row
Wbk.Sheets("ENQUIRY").Range("J23:V" & LastRow).Copy
.Range("A8").PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Wbk.Close False
End With
FileName = ThisWorkbook.Worksheets("Summary").Range("B2")
With Application.FileDialog(4)
.AllowMultiSelect = False
If .Show <> -1 Then Exit Sub
Folder = .SelectedItems(1)
End With
ActiveWorkbook.SaveAs Folder & "\" & FileName & ".xlsx", 51
End Sub