Results 1 to 5 of 5

Thread: VBA Script to Average Amplitude Values in Each Bin Range of a Frequency Histogram

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    VBA Script to Average Amplitude Values in Each Bin Range of a Frequency Histogram

    When running the VBA script below, the script throws a Run-time error and stops as soon as it hits a sound frequency (Freq.) bin which is empty. The script should output an average amplitude (Ave.Amp.) of zero if the bin does not contain any frequency values.

    Can anyone suggest something which might allow the script to run without the run-time error and place a zero in the Ave.Amp. column if there are no frequency values within that particular bin range?

    Thank you.

    Sub Histogram()
    Dim c As Integer, i As Integer, j As Integer
    Dim avg As Double
    Dim binlow As Integer, binhigh As Integer
    Dim N As Integer

    For c = 1 To 16
    binlow = Cells(c + 2, 2)
    binhigh = Cells(c + 3, 2)
    avg = 0
    N = 0
    For i = 1 To 11
    If Cells(i + 2, 6) >= binlow And Cells(i + 2, 6) < binhigh Then
    N = N + 1
    avg = avg + Cells(i + 2, 7)
    End If
    Next i
    avg = avg / N

    Cells(c + 3, 8) = avg
    Next c


    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •