<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://ocotal.iarc.uaf.edu/index.php?action=history&amp;feed=atom&amp;title=Daily_Averages_2</id>
	<title>Daily Averages 2 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://ocotal.iarc.uaf.edu/index.php?action=history&amp;feed=atom&amp;title=Daily_Averages_2"/>
	<link rel="alternate" type="text/html" href="http://ocotal.iarc.uaf.edu/index.php?title=Daily_Averages_2&amp;action=history"/>
	<updated>2026-05-12T22:00:59Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.34.2</generator>
	<entry>
		<id>http://ocotal.iarc.uaf.edu/index.php?title=Daily_Averages_2&amp;diff=738&amp;oldid=prev</id>
		<title>137.229.71.165 at 20:30, 1 August 2008</title>
		<link rel="alternate" type="text/html" href="http://ocotal.iarc.uaf.edu/index.php?title=Daily_Averages_2&amp;diff=738&amp;oldid=prev"/>
		<updated>2008-08-01T20:30:44Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;Copy and paste the text in the box into the visual basic editor that comes with Excel.  To get access to personal.xls in the visual basic editor check out this article: [[Save Macros in Excel]]&lt;br /&gt;
&lt;br /&gt;
This macro and collection of subroutines creates daily averages from hourly data.  It's a pretty general one.  I used it originally with soil temperature strings where there are several columns of data that need to be changed from hourly to daily.  So, there are a couple flags to assist with this.  You can report the day if you'd like and also the number of samples in the 'daily' average for example.  The first subroutine you can use to call the second one which does all the work for you.&lt;br /&gt;
&lt;br /&gt;
Any questions check with Bob. &lt;br /&gt;
&lt;br /&gt;
 Option Explicit&lt;br /&gt;
 Public Sub daily_avg()&lt;br /&gt;
   Dim daycol As Integer&lt;br /&gt;
   Dim inputcol As Integer&lt;br /&gt;
   Dim outcol As Integer&lt;br /&gt;
   Dim worksheetz As Integer&lt;br /&gt;
   Dim startrow As Long&lt;br /&gt;
   Dim outputday As Boolean&lt;br /&gt;
   Dim outputcount As Boolean&lt;br /&gt;
   Dim columnincr As Integer&lt;br /&gt;
   &lt;br /&gt;
   ' stuff that should be set just initially&lt;br /&gt;
   daycol = 1&lt;br /&gt;
   worksheetz = 9&lt;br /&gt;
   startrow = 32&lt;br /&gt;
   outputcount = False&lt;br /&gt;
   outputday = True&lt;br /&gt;
   inputcol = 3&lt;br /&gt;
   outcol = 16&lt;br /&gt;
   Call avg_column(daycol, inputcol, outcol, worksheetz, startrow, outputday, outputcount)&lt;br /&gt;
   outputday = False&lt;br /&gt;
   For columnincr = 0 To 10&lt;br /&gt;
     inputcol = 4 + columnincr&lt;br /&gt;
     outcol = 18 + columnincr&lt;br /&gt;
     Call avg_column(daycol, inputcol, outcol, worksheetz, startrow, outputday, outputcount)&lt;br /&gt;
   Next&lt;br /&gt;
 End Sub&lt;br /&gt;
&lt;br /&gt;
 Public Sub avg_column(daycol As Integer, inputcol As Integer, outcol As Integer, worksheetz As Integer, startrow As Long, outputday As Boolean,  outputcount As Boolean)&lt;br /&gt;
   Dim row As Long&lt;br /&gt;
   Dim count As Integer&lt;br /&gt;
   Dim theday As Integer&lt;br /&gt;
   Dim curdata As Double&lt;br /&gt;
   Dim daysum As Double&lt;br /&gt;
   Dim outrow As Integer&lt;br /&gt;
   &lt;br /&gt;
   outrow = startrow&lt;br /&gt;
   row = startrow&lt;br /&gt;
  &lt;br /&gt;
   theday = Int(Worksheets(worksheetz).Cells(row, daycol).Value)&lt;br /&gt;
   curdata = Worksheets(worksheetz).Cells(row, inputcol).Value&lt;br /&gt;
   If Abs(curdata) &amp;lt; 6999 Then&lt;br /&gt;
     daysum = curdata&lt;br /&gt;
     count = 1&lt;br /&gt;
   End If&lt;br /&gt;
   row = row + 1&lt;br /&gt;
   Do While Worksheets(worksheetz).Cells(row, daycol).Value &amp;lt;&amp;gt; &amp;quot;&amp;quot;&lt;br /&gt;
     If theday = Int(Worksheets(worksheetz).Cells(row, daycol).Value) Then&lt;br /&gt;
       ' same day&lt;br /&gt;
       curdata = Worksheets(worksheetz).Cells(row, inputcol).Value&lt;br /&gt;
       If Abs(curdata) &amp;lt; 6999 Then&lt;br /&gt;
         daysum = daysum + curdata&lt;br /&gt;
         count = count + 1&lt;br /&gt;
       End If&lt;br /&gt;
     Else:&lt;br /&gt;
       ' new day, do some outputting&lt;br /&gt;
       If outputday = True Then&lt;br /&gt;
         ' output the day&lt;br /&gt;
         Worksheets(worksheetz).Cells(outrow, outcol).Value = theday&lt;br /&gt;
         If count &amp;gt; 0 Then&lt;br /&gt;
           ' output daily average&lt;br /&gt;
           Worksheets(worksheetz).Cells(outrow, outcol + 1).Value = daysum / count&lt;br /&gt;
         End If&lt;br /&gt;
         If outputcount = True Then&lt;br /&gt;
           ' output the count if the boolean is true&lt;br /&gt;
           Worksheets(worksheetz).Cells(outrow, outcol + 2).Value = count&lt;br /&gt;
         End If&lt;br /&gt;
       Else:&lt;br /&gt;
         ' don't output the day&lt;br /&gt;
         If count &amp;gt; 0 Then&lt;br /&gt;
           ' output daily average&lt;br /&gt;
           Worksheets(worksheetz).Cells(outrow, outcol).Value = daysum / count&lt;br /&gt;
         End If&lt;br /&gt;
         If outputcount = True Then&lt;br /&gt;
           ' output the count if the boolean is true&lt;br /&gt;
           Worksheets(worksheetz).Cells(outrow, outcol + 1).Value = count&lt;br /&gt;
         End If&lt;br /&gt;
       End If&lt;br /&gt;
       outrow = outrow + 1&lt;br /&gt;
       ' okay, done outputting.  Now to ingest the new data as before.&lt;br /&gt;
       ' first reset the vars.&lt;br /&gt;
       count = 0&lt;br /&gt;
       daysum = 0&lt;br /&gt;
       theday = Int(Worksheets(worksheetz).Cells(row, daycol).Value)&lt;br /&gt;
       curdata = Worksheets(worksheetz).Cells(row, inputcol).Value&lt;br /&gt;
       If Abs(curdata) &amp;lt; 6999 Then&lt;br /&gt;
         daysum = curdata&lt;br /&gt;
         count = 1&lt;br /&gt;
       End If&lt;br /&gt;
       &lt;br /&gt;
     End If     &lt;br /&gt;
     row = row + 1&lt;br /&gt;
   Loop&lt;br /&gt;
     ' drop in the stuff for the last day of year.&lt;br /&gt;
     ' new day, do some outputting&lt;br /&gt;
     If outputday = True Then&lt;br /&gt;
      ' output the day&lt;br /&gt;
      Worksheets(worksheetz).Cells(outrow, outcol).Value = theday&lt;br /&gt;
      If count &amp;gt; 0 Then&lt;br /&gt;
        ' output daily average&lt;br /&gt;
        Worksheets(worksheetz).Cells(outrow, outcol + 1).Value = daysum / count&lt;br /&gt;
      End If&lt;br /&gt;
      If outputcount = True Then&lt;br /&gt;
        ' output the count if the boolean is true&lt;br /&gt;
        Worksheets(worksheetz).Cells(outrow, outcol + 2).Value = count&lt;br /&gt;
      End If&lt;br /&gt;
    Else:&lt;br /&gt;
      ' don't output the day&lt;br /&gt;
      If count &amp;gt; 0 Then&lt;br /&gt;
        ' output daily average&lt;br /&gt;
        Worksheets(worksheetz).Cells(outrow, outcol).Value = daysum / count&lt;br /&gt;
      End If&lt;br /&gt;
      If outputcount = True Then&lt;br /&gt;
        ' output the count if the boolean is true&lt;br /&gt;
        Worksheets(worksheetz).Cells(outrow, outcol + 1).Value = count&lt;br /&gt;
      End If&lt;br /&gt;
    End If&lt;br /&gt;
  End Sub&lt;/div&gt;</summary>
		<author><name>137.229.71.165</name></author>
		
	</entry>
</feed>