Escolar Documentos
Profissional Documentos
Cultura Documentos
totalEnergy = 0
count = 0
rowNum = Range("monthSortEnd").Row
Application.ScreenUpdating = False
Application.EnableEvents = False
ThisWorkbook.Sheets("General Information").Activate
mStart = Range("monthByMonthData").Row
mEnd = Range("monthByMonthDataEnd").Row
Range("monthByMonthData").Select
, DataOption3:=xlSortNormal
'clear all the values before refreshing. cols D, I have calcs so do not clear. these will be cleared
automatically.
sRow = Range("monthSortEnd").Row
Selection.ClearContents
Selection.ClearContents
Selection.ClearContents
Selection.ClearContents
sRow = Range("yearSortEnd").Row
Selection.ClearContents
Range("totEnergy").Select
Selection.ClearContents
For Each c In Range("D" & mStart & ":" & "D" & mEnd)
If count < 12 And Not IsNull(c.Value) And Not c.Value = 0 Then 'check for null energy
If Not IsNull(c.Offset(0, 1).Value) And Not c.Offset(0, 1).Value = 0 Then ' then check for null
cost
c.Select
eUse = c.Value
count = count + 1
rowNum = rowNum - 1 'put the latest values last to avoid another sort for graph axis.
End If
End If
Next
'below 4 categories were split individually cos the values would not be taken from the latest
12months but would fill in from previous data.
count = 0
rowNum = Range("monthSortEnd").Row
For Each c In Range("F" & mStart & ":" & "F" & mEnd)
If count < 12 And Not IsNull(c.Value) And Not c.Value = 0 Then 'check for null energy
If Not IsNull(c.Offset(0, 3).Value) And Not c.Offset(0, 3).Value = 0 Then ' then check for null
cost
c.Select
Range("F" & rowNum) = c.Value
count = count + 1
rowNum = rowNum - 1
End If
End If
Next
count = 0
rowNum = Range("monthSortEnd").Row
For Each c In Range("J" & mStart & ":" & "J" & mEnd)
If count < 12 And Not IsNull(c.Value) And Not c.Value = 0 Then 'check for null energy
If Not IsNull(c.Offset(0, 1).Value) And Not c.Offset(0, 1).Value = 0 Then ' then check for null
cost
c.Select
count = count + 1
rowNum = rowNum - 1
End If
End If
Next
count = 0
rowNum = Range("monthSortEnd").Row
For Each c In Range("L" & mStart & ":" & "L" & mEnd)
If count < 12 And Not IsNull(c.Value) And Not c.Value = 0 Then 'check for null energy
If Not IsNull(c.Offset(0, 1).Value) And Not c.Offset(0, 1).Value = 0 Then ' then check for null
cost
c.Select
count = count + 1
rowNum = rowNum - 1
End If
End If
Next
count = 0
rowNum = Range("monthSortEnd").Row
For Each c In Range("N" & mStart & ":" & "N" & mEnd)
If count < 12 And Not IsNull(c.Value) And Not c.Value = 0 Then 'check for null energy
If Not IsNull(c.Offset(0, 1).Value) And Not c.Offset(0, 1).Value = 0 Then ' then check for null
cost
c.Select
count = count + 1
rowNum = rowNum - 1
End If
End If
Next
count = 0
rowNum = Range("monthSortEnd").Row
For Each c In Range("P" & mStart & ":" & "P" & mEnd)
If count < 12 And Not IsNull(c.Value) And Not c.Value = 0 Then 'check for null energy
If Not IsNull(c.Offset(0, 1).Value) And Not c.Offset(0, 1).Value = 0 Then ' then check for null
cost
c.Select
count = count + 1
rowNum = rowNum - 1
End If
End If
Next
Range("totEnergy").Value = totalEnergy
rowNum = Range("yearSortStart").Row
yStart = Range("yearByYearData").Row
Range("yearByYearData").Select
xlTopToBottom, DataOption1:=xlSortTextAsNumbers
For Each c In Range("C" & yStart & ":" & "C" & yStart + 3) 'leave out the latest since it appear in the
last 12 months(hardcoded on sheet)
c.Select
eUse = c.Value
rowNum = rowNum + 1 'put the earliest values first to avoid another sort for graph axis.
Next
Sheets("General Information").Range("GIDefault").Select
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub