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, (for now just my desktop). 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 and save the file as the name of the product code. Is this possible and if so could anyone point me in the right direction?
Sub Refresh()
Dim Trans As String
Dim Entry As String
Dim Wbk As Workbook
Dim FileName As String
Entry = "C:\Users\Flow\Desktop\Entry Template1"
Trans = "C:\Users\Flow\Desktop\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 = "C:\Users\Flow\Desktop" & ThisWorkbook.Worksheets("Summary").Range("C2")
ActiveWorkbook.SaveAs FileName & ".xlsm", 52
End Sub
Test.xlsm
Bookmarks