仅在vba代码中的正值的平均值

时间:2018-06-12 21:05:52

标签: vba average

如何在我现有的代码中添加代码,这样如果值为正,我只能花24小时?

DayMax = 0                                      'Initialize max to 0
    DayMin = 999999999                              'Initialize min to large number
    DayMean = 0                                     'Initialie mean to 0
    For IHour = 1 To 24                             'For each hour
      Line Input #1, txtLine                        'Read next line
      txtNumber = Mid(txtLine, 12, 10)              'Get the value as string for this line.  This is UNIQUE for each file.  Could also get the date
      HourVal = Val(txtNumber)                      'Convert string to number
      HourVal = HourVal * 1.8 + 32                  'Converts from C to F
      If HourVal > DayMax Then DayMax = HourVal     'If this is above the current max it is the new max
      If HourVal < DayMin Then DayMin = HourVal     'If this is below the current min it is the new min
      DayMean = DayMean + HourVal                   'Add this to the mean, this is a running sum of the values for this day
      Sheets(HourSheet).Cells(IRowHour, IColHour).Value = HourVal     'Save the hourly value
      IRowHour = IRowHour + 1                       'Increment hourl row position
    Next IHour                                      'Go to the next hour
    DayMean = DayMean / 24                          'All done so devide the running sum by 24 to get the daily mean

    'Sheets(DaySheet).Cells(IRowDay, IColDayMin).Value = DayMin     'Save daily values, Put the results where you want them
    'Sheets(DaySheet).Cells(IRowDay, IColDayMax).Value = DayMax
    Sheets(DaySheet).Cells(IRowDay, IColDayMean).Value = DayMean
    IRowDay = IRowDay + 1

  Loop                                              'End of the read loop

  Close #1                                

0 个答案:

没有答案