I have to following code I have been working on for a long time. I have made several tweaks to improve it's efficiency. This is only part of the code, as other parts are similar in text. And help would be greatly appreciated.
Thanks!
Thanks!
Code:
Public data_year As String, data_month As String, data_day As String, count1 As Integer, count2 As Integer, count3 As Integer, count4 As Integer, countT As Integer
Sub Update_Property_Profile()
'Make sure a new copy with the new date has been saved in the folder
Dim Response
Response = MsgBox("Did you create a copy of the profile with newest data date?", vbYesNo, "Continue?")
If Response = vbNo Then
MsgBox "Please create a copy with the new date before continuing.", vbOKOnly, "Create New Copy"
Exit Sub
End If
'Gather the date of the new data
data_year = InputBox("Please enter year:", "What year")
data_month = InputBox("Please enter month (##):", "What month")
data_day = InputBox("Please enter day (##):", "What day")
Response = MsgBox("Is this the correct date: " & data_month & "/" & data_day & "/" & data_year & "?", vbYesNo, "Continue?")
If Response = vbNo Then
MsgBox "I'm sorry, but you have to start over.", vbOKOnly, "Please Try Again"
Exit Sub
End If
'Update the profile with the newewst data
Call Update_monthly_Profile
Call Update_YTD_Profile
'Finishing touches on profile appearance
Call Finish_Profile
End Sub
Sub Update_monthly_Profile()
' *************************************************
' * Update monthly Sales *
' *************************************************
'Open and set up data monthly sheet
Workbooks.Open ("P:\STATE REVIEWS\OH\OH\New Product Set Up\Property\Profile Exhibits\Outputs\" & data_year & data_month & data_day & " Sales - M.xls")
Sheets(1).Name = "Sheet2"
Sheets.Add before:=Sheets(1)
Sheets(2).Range("D:D").AdvancedFilter Action:=xlFilterInPlace, Unique:=True
Sheets(2).Columns("E").Copy Sheets(1).Range("A1")
Sheets(2).Columns("AJ").Copy Sheets(1).Range("B1")
Sheets(2).ShowAllData
'Open and set up monthly sale Profile tab
Workbooks.Open ("P:\STATE REVIEWS\OH\OH\New Product Set Up\Property\Profile Exhibits\Ohio Property Profile v2 " & data_month & data_day & data_year & ".xls")
Set Sales_M = Workbooks(data_year & data_month & data_day & " Sales - M.xls")
Set P_Profile = Workbooks("Ohio Property Profile v2 " & data_month & data_day & data_year & ".xls")
Set P_Macro = Workbooks("Property Profile Macros.xls")
Dim i As Integer
For i = 1 To 5
P_Profile.Sheets(i).Visible = True
Next i
Sheets(5).Range("A4:GL65500").ClearContents
'Filter and paste policy data from data sheet to profile tab
Sales_M.Activate
Sales_M.Sheets(2).Range("E:E").AdvancedFilter Action:=xlFilterInPlace, Unique:=True
Sales_M.Sheets(2).Range("F2:H2", Sheets(2).Range("F2:H2").End(xlDown)).Copy P_Profile.Sheets(5).Range("B3")
Sales_M.Sheets(2).Range("I2:M2", Sheets(2).Range("I2:M2").End(xlDown)).Copy P_Profile.Sheets(5).Range("F3")
Sales_M.Sheets(2).Range("S2:X2", Sheets(2).Range("S2:X2").End(xlDown)).Copy P_Profile.Sheets(5).Range("N3")
Sales_M.Sheets(2).Range("AA2:AG2", Sheets(2).Range("AA2:AG2").End(xlDown)).Copy P_Profile.Sheets(5).Range("Z3")
Sales_M.Sheets(2).Range("AH2", Sheets(2).Range("AH2").End(xlDown)).Copy P_Profile.Sheets(5).Range("AH3")
Sales_M.Sheets(2).Range("AI2", Sheets(2).Range("AI2").End(xlDown)).Copy P_Profile.Sheets(5).Range("AY3")
'Copy down formulas in profile tab
P_Profile.Sheets(5).Activate
Sheets(5).Range("B1").FormulaR1C1 = "=COUNTA(R[3]C:R[65535]C)"
count1 = Sheets(5).Range("B1").Value
Sheets(5).Range("A3").AutoFill Destination:=Range(Cells(3, 1), Cells(count1 + 3, 1))
Sheets(5).Range("E3").AutoFill Destination:=Range(Cells(3, 5), Cells(count1 + 3, 5))
'Show all data from data tab
Sales_M.Sheets(2).ShowAllData
'Paste Formula's into profile data sheet
P_Macro.Sheets(1).Range("CVA_Form").Copy P_Profile.Sheets(5).Range("K3")
Range("K3").Replace What:="20081231", Replacement:=data_year & data_month & data_day, LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("K3").Replace What:="#REF", Replacement:="Sheet2", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("K3").Copy Range("L3")
Range("L3").Replace What:=",12,", Replacement:=",13,", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Sheets(5).Range("K3:L3").AutoFill Destination:=Range(Cells(3, 11), Cells(count1 + 3, 12))
Calculate
Sheets(5).Columns("K:L").Copy
Sheets(5).Columns("K:L").PasteSpecial xlPasteValues
P_Macro.Sheets(1).Range("WH_Form").Copy P_Profile.Sheets(5).Range("M3")
Range("M3").Replace What:="20081231", Replacement:=data_year & data_month & data_day, LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("M3").Replace What:="#REF", Replacement:="Sheet2", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Sheets(5).Range("M3").AutoFill Destination:=Range(Cells(3, 13), Cells(count1 + 3, 13))
Calculate
Sheets(5).Columns("M:M").Copy
Sheets(5).Columns("M:M").PasteSpecial xlPasteValues
P_Macro.Sheets(1).Range("MP_Form").Copy P_Profile.Sheets(5).Range("T3")
Range("T3").Replace What:="20081231", Replacement:=data_year & data_month & data_day, LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("T3").Replace What:="#REF", Replacement:="Sheet2", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Sheets(5).Range("T3").AutoFill Destination:=Range(Cells(3, 20), Cells(count1 + 3, 20))
Calculate
Sheets(5).Columns("T:T").Copy
Sheets(5).Columns("T:T").PasteSpecial xlPasteValues
P_Macro.Sheets(1).Range("LC_Form").Copy P_Profile.Sheets(5).Range("W3")
Range("W3").Replace What:="20081231", Replacement:=data_year & data_month & data_day, LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("W3").Replace What:="#REF", Replacement:="Sheet2", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Sheets(5).Range("W3").AutoFill Destination:=Range(Cells(3, 23), Cells(count1 + 3, 23))
P_Macro.Sheets(1).Range("NP_Form").Copy P_Profile.Sheets(5).Range("X3")
Range("X3").Replace What:="20081231", Replacement:=data_year & data_month & data_day, LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("X3").Replace What:="#REF", Replacement:="Sheet2", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Sheets(5).Range("X3").AutoFill Destination:=Range(Cells(3, 24), Cells(count1 + 3, 24))
P_Macro.Sheets(1).Range("RC_Form").Copy P_Profile.Sheets(5).Range("Y3")
Range("Y3").Replace What:="20081231", Replacement:=data_year & data_month & data_day, LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("Y3").Replace What:="#REF", Replacement:="Sheet2", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Sheets(5).Range("Y3").AutoFill Destination:=Range(Cells(3, 25), Cells(count1 + 3, 25))
Calculate
Sheets(5).Columns("W:Y").Copy
Sheets(5).Columns("W:Y").PasteSpecial xlPasteValues
P_Macro.Sheets(1).Range("Assoc_Form").Copy P_Profile.Sheets(5).Range("U3")
Range("U3").Replace What:="20081231", Replacement:=data_year & data_month & data_day, LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("U3").Replace What:="#REF", Replacement:="Sheet2", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Sheets(5).Range("U3").AutoFill Destination:=Range(Cells(3, 21), Cells(count1 + 3, 21))
P_Macro.Sheets(1).Range("PD_Form").Copy P_Profile.Sheets(5).Range("V3")
Range("V3").Replace What:="20081231", Replacement:=data_year & data_month & data_day, LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("V3").Replace What:="#REF", Replacement:="Sheet2", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Sheets(5).Range("V3").AutoFill Destination:=Range(Cells(3, 22), Cells(count1 + 3, 22))
Calculate
Sheets(5).Columns("U:V").Copy
Sheets(5).Columns("U:V").PasteSpecial xlPasteValues
P_Macro.Sheets(1).Range("OT_Form").Copy P_Profile.Sheets(5).Range("AG3")
Range("AG3").Replace What:="20081231", Replacement:=data_year & data_month & data_day, LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("AG3").Replace What:="#REF", Replacement:="Sheet2", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Sheets(5).Range("AG3").AutoFill Destination:=Range(Cells(3, 33), Cells(count1 + 3, 33))
Calculate
Sheets(5).Columns("AG:AG").Copy
Sheets(5).Columns("AG:AG").PasteSpecial xlPasteValues
P_Macro.Sheets(1).Range("HM_Form").Copy P_Profile.Sheets(5).Range("AI3")
Range("AI3").Replace What:="20081231", Replacement:=data_year & data_month & data_day, LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("AI3").Replace What:="#REF", Replacement:="Sheet2", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Sheets(5).Range("AI3").AutoFill Destination:=Range(Cells(3, 35), Cells(count1 + 3, 35))
P_Macro.Sheets(1).Range("ML55_Form").Copy P_Profile.Sheets(5).Range("AJ3")
Range("AJ3").Replace What:="20081231", Replacement:=data_year & data_month & data_day, LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("AJ3").Replace What:="#REF", Replacement:="Sheet2", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Sheets(5).Range("AJ3").AutoFill Destination:=Range(Cells(3, 36), Cells(count1 + 3, 36))
Sheets(5).Range("AJ3").Copy Sheets(5).Range("AL3")
Range("AL3").Replace What:="&$AJ$1", Replacement:="&$AL$1", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Sheets(5).Range("AJ3").Copy Sheets(5).Range("AM3")
Range("AM3").Replace What:="&$AJ$1", Replacement:="&$AM$1", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Sheets(5).Range("AL3:AM3").AutoFill Destination:=Range(Cells(3, 38), Cells(count1 + 3, 39))
P_Macro.Sheets(1).Range("ML208_Form").Copy P_Profile.Sheets(5).Range("AK3")
Range("AK3").Replace What:="20081231", Replacement:=data_year & data_month & data_day, LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("AK3").Replace What:="#REF", Replacement:="Sheet2", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Sheets(5).Range("AK3").AutoFill Destination:=Range(Cells(3, 37), Cells(count1 + 3, 37))
Sheets(5).Range("AK3").Copy Sheets(5).Range("AN3")
Range("AN3").Replace What:="&$AK$1", Replacement:="&$AN$1", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Sheets(5).Range("AN3").AutoFill Destination:=Range(Cells(3, 40), Cells(count1 + 3, 40))
P_Macro.Sheets(1).Range("ML61_Form").Copy P_Profile.Sheets(5).Range("AO3")
Range("AO3").Replace What:="20081231", Replacement:=data_year & data_month & data_day, LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("AO3").Replace What:="#REF", Replacement:="Sheet2", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Sheets(5).Range("AO3").Copy Sheets(5).Range("AP3")
Range("AP3").Replace What:="&$AO$1", Replacement:="&$AP$1", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Sheets(5).Range("AO3").Copy Sheets(5).Range("AQ3")
Range("AQ3").Replace What:="&$AO$1", Replacement:="&$AQ$1", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Sheets(5).Range("AO3").Copy Sheets(5).Range("AR3")
Range("AR3").Replace What:="&$AO$1", Replacement:="&$AR$1", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Sheets(5).Range("AO3").Copy Sheets(5).Range("AS3")
Range("AS3").Replace What:="&$AO$1", Replacement:="&$AS$1", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Sheets(5).Range("AO3").Copy Sheets(5).Range("AT3")
Range("AT3").Replace What:="&$AO$1", Replacement:="&$AT$1", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Sheets(5).Range("AO3").Copy Sheets(5).Range("AU3")
Range("AU3").Replace What:="&$AO$1", Replacement:="&$AU$1", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Sheets(5).Range("AO3").Copy Sheets(5).Range("AV3")
Range("AV3").Replace What:="&$AO$1", Replacement:="&$AV$1", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Sheets(5).Range("AO3").Copy Sheets(5).Range("AW3")
Range("AW3").Replace What:="&$AO$1", Replacement:="&$AW$1", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Sheets(5).Range("AO3").Copy Sheets(5).Range("AX3")
Range("AX3").Replace What:="&$AO$1", Replacement:="&$AX$1", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Sheets(5).Range("AO3:AX3").AutoFill Destination:=Range(Cells(3, 41), Cells(count1 + 3, 50))
Calculate
Sheets(5).Columns("AI:AX").Copy
Sheets(5).Columns("AI:AX").PasteSpecial xlPasteValues
P_Macro.Sheets(1).Range("Prem_Form").Copy P_Profile.Sheets(5).Range("AZ3")
Range("AZ3").Replace What:="20081231", Replacement:=data_year & data_month & data_day, LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("AZ3").Replace What:="#REF", Replacement:="Sheet1", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("AZ3").Replace What:="Sheet2", Replacement:="Sheet1", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Range("AZ3").Replace What:=",$A$3,", Replacement:=",$A3,", LookAt:= _
xlPart, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Sheets(5).Range("AZ3").AutoFill Destination:=Range(Cells(3, 52), Cells(count1 + 3, 52))
Calculate
Sheets(5).Columns("AZ:AZ").Copy
Sheets(5).Columns("AZ:AZ").PasteSpecial xlPasteValues
'Update formulas for counts
Sheets(5).Range("BA3:GL3").AutoFill Destination:=Range(Cells(3, 53), Cells(count1 + 3, 194))
Calculate
'Save and close monthly sales data workbook
Sales_M.Application.DisplayAlerts = False
Sales_M.Sheets(1).Delete
Sales_M.Application.DisplayAlerts = True
Sales_M.Save
Sales_M.Close