View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Bob Phillips[_6_] Bob Phillips[_6_] is offline
external usenet poster
 
Posts: 11,272
Default Value# in VBA script with reference

Sounds like you are trying to assign a string to a long variable. Check all
of those cells that they contain numeric data.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"TMJ Vermeer" wrote in message
ups.com...
Hi,

I'm not a specialist in VBA, but also not a newbee (I think).
I try to get the contence of a cell from a different worksheet but I
get the message: VALUE#
(A value used in the formula is of the wrong data type). What am I
doing wrong!
Below the function.

Function CalcValue(pVal) As Long

If pVal = 1 Then
CalcValue = wegingsfactoren!D3

ElseIf pVal = 2 Then
CalcValue = wegingsfactoren!D4

ElseIf pVal = 3 Then
CalcValue = wegingsfactoren!D5

ElseIf pVal = 4 Then
CalcValue = wegingsfactoren!D6

ElseIf pVal = 5 Then
CalcValue = wegingsfactoren!D7

ElseIf pVal = 6 Then
CalcValue = wegingsfactoren!D8

ElseIf pVal = 7 Then
CalcValue = wegingsfactoren!D9

ElseIf pVal = 8 Then
CalcValue = wegingsfactoren!D10

ElseIf pVal = 9 Then
CalcValue = wegingsfactoren!D11

ElseIf pVal = 10 Then
CalcValue = wegingsfactoren!D12

ElseIf pVal = 11 Then
CalcValue = wegingsfactoren!D13

ElseIf pVal = 12 Then
CalcValue = wegingsfactoren!D14

ElseIf pVal = 13 Then
CalcValue = wegingsfactoren!D15

ElseIf pVal = 14 Then
CalcValue = wegingsfactoren!D16

ElseIf pVal = 15 Then
CalcValue = wegingsfactoren!D17

ElseIf pVal = 16 Then
CalcValue = wegingsfactoren!D18

ElseIf pVal = 17 Then
CalcValue = wegingsfactoren!D19

ElseIf pVal = 18 Then
CalcValue = wegingsfactoren!D20

Else
CalcValue = 0
End If

End Function

Thanks

Theo Vermeer