1. This is my exercise:

there is a file in Excel with in column A the names of the mountains and the height in column B. I have to write a subprocedure that determines the average of the heights and the heighest mountain and writes the name in a MsgBox.

The previous part of the exercise goes as following:

Option Explicit

Sub bergen()

Dim histogram(13) As Integer
Dim frequentietabel(13) As String

frequentietabel(1) = "100 - 200 m"
frequentietabel(2) = "200 - 300 m"
frequentietabel(3) = "300 - 400 m"
frequentietabel(4) = "400 - 500 m"

i = 2
Do While Not Worksheets("bergen").Cells(i, 2) = ""
hoogte = Worksheets("bergen").Cells(i, 2)
histogram(hoogte \ 100) = histogram(hoogte \ 100) + 1
i = i + 1
Loop

x = vbCr
i = 1
For i = 1 To 13
x = x & histogram(i) & vbCr
Next i

MsgBox x

End Sub

Now I have no idea how to begin. Is it possible to start from the previous part of the exercise or does it have to be a new procedure?

Thanks!

2.

3. Okay, I noticed this was an incomplete version.
Anyways, I came up with a solution, but I become the value 0 for my average (gemiddelde). I thought I'd make an addition of the heights of the mountain (som) and divide that by the amount of mountains (aantal)

Sub bergen_b()

Dim i As Integer, aantal As Integer
Dim gemiddelde As Integer, max As Integer, som As Integer
Dim hoogste_top As String

i = 2
Do While Not Worksheets("bergen").Cells(i, 2) = ""
som = Worksheets("bergen").Cells(i, 2)
aantal = aantal + 1
gemiddelde = som / aantal
If Worksheets("bergen").Cells(i, 2) > Worksheets("bergen").Cells(i - 1, 2) Then
max = Worksheets("bergen").Cells(i, 2)
End If

Can someone point out my mistake?

Thanks!
If Worksheets("bergen").Cells(i, 2) = max Then
hoogste_top = Worksheets("bergen").Cells(i, 1)
End If
i = i + 1
Loop

MsgBox "De gemiddelde hoogte bedraagt " & gemiddelde & ". De hoogste top in Schotland is " & hoogste_top & "."

End Sub

 Bookmarks
##### Bookmarks
 Posting Permissions
 You may not post new threads You may not post replies You may not post attachments You may not edit your posts   BB code is On Smilies are On [IMG] code is On [VIDEO] code is On HTML code is Off Trackbacks are Off Pingbacks are Off Refbacks are On Terms of Use Agreement