Hi ...
The click event on the update button calls the following Sub Update ... and there are 2 other calls within the Sub Update that are listed below as well ...
Thanks
Sub Update()
startpoint = Range("startrow").Value
Sheets("Results").Select
' clear all the data from the current month and start from there to get new data
Range("A" & startpoint & ":G" & startpoint & "").Select
Range("G" & startpoint & "").Activate
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
Range("H3:K3").Activate
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
Sheets("Completed Steam Jobs").Select
' get completed job data from the data warehouse, uses beginning of the first
' month without data as a start date
Call Completed_Steam
' find the last row with data and start filling in new data at the next row
maxindex = Range("J1").Value
fillto = maxindex + startpoint - 1
' j is index for the completed steam jobs sheet
j = 2
For i = startpoint To startpoint + maxindex - 1
' get completed job information: start date, end date, recommended volume
Sheets("Completed Steam Jobs").Select
wellname = Range("B" & j & "").Value
leasename = Range("C" & j & "").Value
steamto = Range("D" & j & "").Value
steamfrom = Range("G" & j & "").Value
reqvolume = Range("F" & j & "").Value
jobtype = Range("E" & j & "").Value
Sheets("DSS Steam Data").Select
Range("G2").FormulaR1C1 = steamfrom
Range("G3").FormulaR1C1 = steamto
Range("F2").FormulaR1C1 = wellname
Call steam_from_DSS
actsteam = Range("E2").Value
' paste all the values into the results page
Sheets("Results").Select
Range("A" & i & "").FormulaR1C1 = wellname
Range("B" & i & "").FormulaR1C1 = steamto
Range("C" & i & "").FormulaR1C1 = steamfrom
Range("D" & i & "").FormulaR1C1 = jobtype
Range("E" & i & "").FormulaR1C1 = reqvolume
Range("F" & i & "").FormulaR1C1 = actsteam
Range("G" & i & "").FormulaR1C1 = leasename
j = j + 1
Next i
' fill down the formulas
Range("H2:K2").Select
Selection.AutoFill Destination:=Range("H2:K" & fillto & "")
' refresh the pivot tables
Sheets("Spec Pivot").Select
Range("A4").Select
ActiveSheet.PivotTables("PivotTable2").PivotCache.Refresh
Sheets("SM outside Spec Pivot").Select
Range("A1").Select
ActiveSheet.PivotTables("PivotTable2").PivotCache.Refresh
Sheets("Moco Spec Pivot").Select
Range("A1").Select
ActiveSheet.PivotTables("PivotTable2").PivotCache.Refresh
' Application.ScreenUpdating = True
Sheets("Spec line Chart").Select
End Sub
Sub Completed_Steam()
Sheets("Completed Steam Jobs").Select
startdate = Format(Range("startdate").Value, "yyyy-mm-dd")
Range("A1").Select
With Selection.QueryTable
.Connection = Array(Array( _
"ODBC;DSN= my dsn goes here
.CommandText = Array( _
"SELECT DISTINCT DSS_WELL_MASTER.FLD_NME, DSS_WELL_MASTER.NAME, DSS_WELL_MASTER.STRG_NME, CYCLC_STM_REQT_FACT.CMPL_DTTM, CYCLC_STM_REQT_FACT.STRT_DTTM, CYCLC_STM_REQT_FACT.STM_DLVY_TYPE_ID, CYCLC_STM_R" _
, _
"EQT_FACT.TGT_STM_VOL_QTY" & Chr(13) & "" & Chr(10) & "FROM DWRPTG.CMPL_DMN CMPL_DMN, DWRPTG.CYCLC_STM_REQT_FACT CYCLC_STM_REQT_FACT, DSS.DSS_WELL_MASTER DSS_WELL_MASTER" & Chr(13) & "" & Chr(10) & "WHERE CYCLC_STM_REQT_FACT.CMPL_FAC_ID = CMPL_DMN.CMPL_FAC_" _
, _
"ID AND CMPL_DMN.WELL_API_NBR = DSS_WELL_MASTER.WELL_API_NBR AND ((CYCLC_STM_REQT_FACT.CMPL_DTTM>={ts '" & startdate & " 00:00:00'}) AND (DSS_WELL_MASTER.FLD_NME='MWSS'))" & Chr(13) & "" & Chr(10) & "ORDER BY CYCLC_STM_REQT_FAC" _
, "T.CMPL_DTTM ASC")
.Refresh BackgroundQuery:=False
End With
End Sub
Sub steam_from_DSS()
well = Sheets("DSS Steam Data").Range("well").Value
steamto = Format(Sheets("DSS Steam Data").Range("steamto").Value, "yyyy-mm-dd")
steamfrom = Format(Sheets("DSS Steam Data").Range("steamfrom").Value, "yyyy-mm-dd")
Range("A1").Select
With Selection.QueryTable
.Connection = Array(Array( _
"ODBC; my dsn goes here
.CommandText = Array( _
"SELECT distinct CMPL_DMN.CMPL_NME, CMPL_DLY_FACT.EFTV_DTTM, CMPL_DLY_FACT.ALOC_CYCL_STM_INJ_VOL_QTY" & Chr(13) & "" & Chr(10) & "FROM VOLRPTG.CMPL_DLY_FACT CMPL_DLY_FACT, DWRPTG.CMPL_DMN CMPL_DMN" & Chr(13) & "" & Chr(10) & "WHERE CMPL_DLY_FACT.CMPL_FAC_ID = CMPL_D" _
, _
"MN.CMPL_FAC_ID AND ((CMPL_DMN.CMPL_NME='" & well & "') AND (CMPL_DLY_FACT.EFTV_DTTM between {ts '" & steamfrom & " 00:00:00'} And {ts '" & steamto & " 00:00:00'}))" _
)
.Refresh BackgroundQuery:=False
End With
End Sub