You don't need code to do this. Just need a couple of tricks
  1. highlight the the cells containing all the data (ie A1:A200). Make sure that the last cell in your selection is the last blank cell).
  2. Use the command GOTO\SPECIAL\BLANKS (press F5 to bring up the GOTO Dialogue)
  3. Then use the AutoSum button and select the average function.

that should do what you want