I am having trouble finding the volume of a tank for an Excel VBA course; I am to make a VBA function, which I input the radius, height, and depth of the tank, and receive the volume. Here is a picture for a better understanding:

This is the code I currently have, which the course tells me is incorrect:
Option Explicit
Function tank(R As Double, d As Double, H As Double) As Double
Dim pi As Double
pi = Application.WorksheetFunction.pi()
If d <= R Then
tank = pi * d ^ 2 / 3 * (3 * R - d)
ElseIf R < d And d <= H - R Then
tank = 2 / 3 * pi * R ^ 3 + pi * R ^ 2 * (d - R)
ElseIf H - R < d And d <= H Then
tank = 4 / 3 * pi * R ^ 3 + pi * R ^ 2 * (H - 2 * R) - pi * (H - d) ^ 2 / 3 * (3 * R - H + d)
End If
End Function
Could anyone help me with this problem? (I am using a macro provided by my course instructor, which does not tell me what is wrong, but if it is wrong or correct.)