title: This is my first time programming in VBA, I do not get any return values for MolarVolume
body: <p>no matter what I plug in, I get a Value error #Value! Is there a problem with the way my function is written, used to C++ and Matlab. Could anyone please tell me what I'm doing wrong. This is a function to calculate the Molar Volume of a compound from 3 different Datasets for different Values. The logic In my opinion (feel free to correct) seems to be fine. It's just that I am not used to the Visual Basic Syntax. If there are any logical or syntax related errors please please please tell me. All help will be appreciated. Thank you in advance! </p>
  
  <pre><code>Function MolarVolume(compund As String, T As Double, P As Double) As Double
  T = 273.15 + T
  Dim Compare As String
  Dim Z01 As Double  
  Dim Z02 As Double
  Dim Z0 As Double
  Dim Tc As Double
  Dim Pc As Double
  Dim Z11 As Double
  Dim Z12 As Double
  Dim Z1 As Double
  Dim Pr As Double
  Dim Pr1 As Double
  Dim Pr2 As Double
  Dim col As Integer
  Dim Row As Integer
  Dim ComparePressureZ As Double
  Dim CompareTempZ As Double
  
  Set Data = Worksheets("data").Activate
  
  Compare = Data.Cells(Row, 1)
  
  
  While Compare &lt;&gt; compound
  Row = Row + 1
  Compare = Data.Cells(Row, 1)
  Wend
  
  Tc = Data.Cells(Row, 4)
  Pc = Data.Cells(Row, 5)
  
  Tr = T / Tc
  Pr = P / Pc  
  
  Tr = Round(Tr, 1)
  
  
  Set Dataz0 = Worksheets("data_Z0.csv").Activate
  
  col = 1
  Row = 1
  
  
  ComparePressureZ = Dataz0.Cells(1, col)
  CompareTempZ = Dataz0.Cells(Row, col)
  
  While ComparePressureZ &lt; Round(Pr, 1)
  col = col + 1
  Pr1 = Dataz0.Cells(1, col)
  While CompareTempZ &lt;&gt; Tr
  Row = Row + 1
  Wend
  Z01 = Dataz0.Cells(Row, col)
  Wend
  
  
  
  Set Rng = Range("B1:P1")
  Row = 1
  col = 2
  
  
  For Each cll In Rng
  If cll.Value &gt; Pr Then
  col = col
  Pr2 = Dataz0.Cells(1, col)
  Else
  col = col + 1
  End If
  Next
  
  
  While CompareTempZ &lt;&gt; Tr
  Row = Row + 1
  Wend
  
  
  Z02 = Dataz0.Cells(Row, col)
  
  
  Z0 = Z01 + (Pr - Pr1) * ((Z02 - Z01) / (Pr2 - Pr1))
  
  
  Set dataz1 = Worksheets("data_Z1.csv").Activate
  
  col = 1
  Row = 1
  
  ComparePressureZ = dataz1.Cells(1, col)
  CompareTempZ = dataz1.Cells(Row, col)
  
  While ComparePressureZ &lt; Round(Pr, 1)
  col = col + 1
  Pr1 = dataz1.Cells(1, col)
  While CompareTempZ &lt;&gt; Tr
  Row = Row + 1
  Wend
  Z11 = dataz1.Cells(Row, col)
  Wend
  
  
  
  Set Rng = Range("B1:P1")
  Row = 1
  col = 2
  
  
  For Each cll In Rng
  If cll.Value &gt; Pr Then
  col = col
  Pr2 = dataz1.Cells(1, col)
  Else
  col = col + 1
  End If
  Next
  
  
  While CompareTempZ &lt;&gt; Tr
  Row = Row + 1
  Wend
  
  
  Z12 = dataz1.Cells(Row, col)
  
  
  Z1 = Z11 + (Pr - Pr1) * ((Z12 - Z11) / (Pr2 - Pr1))
  
  
  MolarVolume = Z1
  
  
  End Function    
  </code></pre>