I'm trying to copy and paste a customer number from cell A2, into a template (different document). The template performs various VLOOKUPs against the same document that the customer number came from. Then, I want to save the template as the customer's id (the value that is now in cell K7 on the template), and move onto the next customer number (A3, then A4, etc.); until the end of the file.
For some reason, I'm getting an error at the font in red. I'm not sure why, as I've used the same code in a different Sub elsewhere.
For some reason, I'm getting an error at the font in red. I'm not sure why, as I've used the same code in a different Sub elsewhere.
VBA Code:
Sub CreateDocuments()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Dim m, s As Workbook
Dim mCD, mTH, sMS1 As Worksheet
Dim mCDLR As Long
Dim Rng, c As Range
Dim fPath, fName As String
Set m = ThisWorkbook
Set mCD = ThisWorkbook.Sheets("Core_Data")
Set mTH = ThisWorkbook.Sheets("TranHist")
Set s = Workbooks.Open("\\Location\DocumentTemplate.xlsx")
[COLOR=rgb(226, 80, 65)]Set sMS1 = s.Worksheets("MS1")[/COLOR]
mCDLR = mCD.Range("A" & Rows.Count).End(xlUp).Row
Set Rng = mCD.Range("A2:A" & mCDLR)
fPath = "\\Location\Today's Documents\"
'fName = sws.Range("K7").Value & ".xlsx"
For Each c In Rng
fName = sMS1.Range("K7").Value & ".xlsx"
If c <> "" Then
c.Copy
sMS1.Range("K7").PasteSpecial xlPasteValues
s.SaveAs fPath & fName
End If
Next
Application.DisplayAlerts = True
Application.DisplayAlerts = True
End Sub