J
JAUrrutia9
....I hope. I just started doing my own VBA Programming and I'm stuck.
I've created a formula that is just a series of nested ifs (12). I'd
like to be able to dragged the cell containing the formula and have the
REF change as I drag it, but right now the formula is not variable and
REF's only one set of cells when I try to drag it. here's my
formula...
Function CalcDate(pVal As String) As Long
If pVal = "1" Then
CalcDate = Range("I4").Value
ElseIf pVal = "2" Then
CalcDate = Range("I12").Value
ElseIf pVal = "3" Then
CalcDate = Range("I20").Value
ElseIf pVal = "4" Then
CalcDate = Range("I28").Value
ElseIf pVal = "5" Then
CalcDate = Range("I36").Value
ElseIf pVal = "6" Then
CalcDate = Range("I44").Value
ElseIf pVal = "7" Then
CalcDate = Range("O4:S4").Value
ElseIf pVal = "8" Then
CalcDate = Range("O12:S12").Value
ElseIf pVal = "9" Then
CalcDate = Range("O20").Value
ElseIf pVal = "10" Then
CalcDate = Range("O28").Value
ElseIf pVal = "11" Then
CalcDate = Range("O36").Value
ElseIf pVal = "12" Then
CalcDate = Range("O44").Value
Else
CalcValue = 0
End If
End Function
.....Please help!
I've created a formula that is just a series of nested ifs (12). I'd
like to be able to dragged the cell containing the formula and have the
REF change as I drag it, but right now the formula is not variable and
REF's only one set of cells when I try to drag it. here's my
formula...
Function CalcDate(pVal As String) As Long
If pVal = "1" Then
CalcDate = Range("I4").Value
ElseIf pVal = "2" Then
CalcDate = Range("I12").Value
ElseIf pVal = "3" Then
CalcDate = Range("I20").Value
ElseIf pVal = "4" Then
CalcDate = Range("I28").Value
ElseIf pVal = "5" Then
CalcDate = Range("I36").Value
ElseIf pVal = "6" Then
CalcDate = Range("I44").Value
ElseIf pVal = "7" Then
CalcDate = Range("O4:S4").Value
ElseIf pVal = "8" Then
CalcDate = Range("O12:S12").Value
ElseIf pVal = "9" Then
CalcDate = Range("O20").Value
ElseIf pVal = "10" Then
CalcDate = Range("O28").Value
ElseIf pVal = "11" Then
CalcDate = Range("O36").Value
ElseIf pVal = "12" Then
CalcDate = Range("O44").Value
Else
CalcValue = 0
End If
End Function
.....Please help!