Private Sub FishWeight()
Option Specific
Dim W As Integer
If Range("C3").Value = "LMB" Then W = Range("E3").Value ^ 2 / 1200
If Range("C3").Value = "SMB" Then W = Range("E3").Value ^ 2 / 1200
If Range("C3").Value="RAINBOW" Then W = Range("E3").Value. ^2/1200
If C3 = ("Rainbow") Then W = E3 * F3 ^ 2 / 800
If C3 = ("Brown") Then W = E3 * F3 ^ 2 / 800
If C3 = ("Saugeye") Then W = E3 ^ 3 / 2700
If C3 = ("Walleye") Then W = E3 ^ 3 / 2700
If C3 = ("Muskie") Then W = E3 ^ 3 / 3500
If C3 = ("Northern") Then W = E3 ^ 3 / 3500
End If
End Sub
Since I see what you are doing, you do need a FUNCTION vs. a Sub:
1. It's Option Explicit V. Specific and it should be the first line in the module
2. When you use a function, you pass values from the worksheet or another macro in a parameter list in parentheses after the function name.
3. The function must return a value to the cell it is entered in. You do this by declaring the type of the function at the end of the declaration line so that the first line of the function looks like:
Public Function FishWeight(ByVal Species as String) As Long
then in column J you have
J3: =FishWeight(C3)
The C3 in parentheses will pass the data in C3 to the function for calculations.
then the function will return the value calculated with the number in cell C3 to cell J3.
However, the function must be set to the calculated value. You held the calculated value in a variable "W" but instead you needed a line like:
FishWeight = Range("E3").Value ^ 2 / 1200; replacing every instance of "W" with "Fishweight".
Your line(s):If Range("C3").Value = "LMB" Then W = Range("E3").Value ^ 2 / 1200, etc
should be: If Range("C3").Value = "LMB" Then FishWeight = Range("E3").Value ^ 2 / 1200
In the attachment, I used the Select Case structure instead of the IF's, thought the IF's are ok, here
Bookmarks