Thanks for you help on this. I'm having some difficulty tailoring your code to my needs. The number of records and ranges will change each month. To further complication the process the range copied is rarely contiguous.
Here's what I currently have that creates the .csv file:
Sub ExportCSV(strPath As String, strExtractFile As String)
'Calculate workbook to ensure timestamp is updated
Application.CalculateFullRebuild
'Create new workbook, assign variables
Dim wbkExport As Workbook 'destination file for data to export
Set wbkExport = Workbooks.Add
Dim shtExport As Worksheet 'destination worksheet for data to export
Set shtExport = wbkExport.Sheets(1)
'Copy data from output tab to new worksheet
Dim lngValnDtCnt As Long 'valuation date count
lngValnDtCnt = shtAdmin.Range("ValnDtCnt").Value
'IP estimates
shtOutput.Range("A2:G" & lngValnDtCnt - 11).Copy
shtExport.Range("B2:H" & lngValnDtCnt - 11).PasteSpecial xlPasteValuesAndNumberFormats
Application.CutCopyMode = False
'OP estimates
shtOutput.Range("A38:G" & lngValnDtCnt + 25).Copy
shtExport.Range("B" & (lngValnDtCnt - 10) & ":H" & ((2 * lngValnDtCnt) - 23)).PasteSpecial _
xlPasteValuesAndNumberFormats
Application.CutCopyMode = False
'PHYS estimates
shtOutput.Range("A74:G" & lngValnDtCnt + 61).Copy
shtExport.Range("B" & ((2 * lngValnDtCnt) - 22) & ":H" & ((3 * lngValnDtCnt) - 35)).PasteSpecial _
xlPasteValuesAndNumberFormats
Application.CutCopyMode = False
'RX estimates
shtOutput.Range("A110:G" & lngValnDtCnt + 97).Copy
shtExport.Range("B" & ((3 * lngValnDtCnt) - 34) & ":H" & ((4 * lngValnDtCnt) - 47)).PasteSpecial _
xlPasteValuesAndNumberFormats
Application.CutCopyMode = False
'Create header record in new worksheet
shtExport.Range("A1").Value = strExtractFile
'shtExport.Range("B1").Value = Format(shtAdmin.Range("ValnDt"), "yyyymmdd")
shtExport.Range("B1").Value = Format(Now(), "yyyymmdd")
shtExport.Range("C1").Value = (4 * lngValnDtCnt) - 48
shtExport.Range("D1").Value = Format(Application.Sum(shtOutput.Range("E2:E145")), "Fixed")
shtExport.Range("D1").NumberFormat = "0.00"
shtExport.Range("E1").Value = Format(Application.Sum(shtOutput.Range("F2:F145")), "Fixed")
shtExport.Range("E1").NumberFormat = "0.00"
'Save CSV file
wbkExport.SaveAs Filename:=strPath & strExtractFile, FileFormat:=xlCSV
wbkExport.Close saveChanges:=False
End Sub
Bookmarks