-
Solved: Compiler error: Object required.
Hello.
I´m having a bit problems solving my problem. I can´t seem to figure out where the problem is?
I get an compiler error saying Object required.
I have the following code.
[vba]Global CellNyStdInvEgen As Double
Global CellNyStdInvFaelles As Double
Global CellNyTaetLavFaelles As Double
Global CellNyTaetLavEgen As Double
Global CellNyLejlFaelles As Double
Global CellNyUngdomFaelles As Double
Global CellNyEnfasede As Double
Global CellNyLevOver25A As Double
Global CellNyPrKW As Double
Global CellNyFremtid As Double
Global CellNyTotal As Double
Global TestType As String
Sub AssignCells()
' Ny Installation
If ActiveWorkbook.Worksheets(1).Range("F12").Value <> "" Then
CellNyStdInvEgen = ActiveWorkbook.Worksheets(1).Range("F12").Value
ElseIf ActiveWorkbook.Worksheets(1).Range("F13").Value <> "" Then
CellNyStdInvFaelles = ActiveWorkbook.Worksheets(1).Range("F13").Value
ElseIf ActiveWorkbook.Worksheets(1).Range("F14").Value <> "" Then
CellNyTaetLavFaelles = ActiveWorkbook.Worksheets(1).Range("F14").Value
ElseIf ActiveWorkbook.Worksheets(1).Range("F15").Value <> "" Then
CellNyTaetLavEgen = ActiveWorkbook.Worksheets(1).Range("F15").Value
ElseIf ActiveWorkbook.Worksheets(1).Range("F16").Value <> "" Then
CellNyLejlFaelles = ActiveWorkbook.Worksheets(1).Range("F16").Value
ElseIf ActiveWorkbook.Worksheets(1).Range("F17").Value <> "" Then
CellNyUngdomFaelles = ActiveWorkbook.Worksheets(1).Range("F17").Value
ElseIf ActiveWorkbook.Worksheets(1).Range("F18").Value <> "" Then
CellNyEnfasede = ActiveWorkbook.Worksheets(1).Range("F18").Value
ElseIf ActiveWorkbook.Worksheets(1).Range("F20").Value <> "" Then
CellNyLevOver25A = ActiveWorkbook.Worksheets(1).Range("F20").Value
ElseIf ActiveWorkbook.Worksheets(1).Range("F21").Value <> "" Then
CellNyPrKW = ActiveWorkbook.Worksheets(1).Range("F21").Value
ElseIf ActiveWorkbook.Worksheets(1).Range("F22").Value <> "" Then
CellNyFremtid = ActiveWorkbook.Worksheets(1).Range("F22").Value
End If
CellNyTotal = ActiveWorkbook.Worksheets(1).Range("F24").Value
End Sub
Private Function PickValue(Row As Integer, InvType As String) As Double
Dim returnVal As Double
Select Case Row
Case 1
Set returnVal = CellNyStdInvEgen
Case 2
Set returnVal = CellNyStdInvFaelles
Case 3
Set returnVal = CellNyTaetLavFaelles
Case 4
Set returnVal = CellNyTaetLavEgen
Case 5
Set returnVal = CellNyLejlFaelles
Case 6
Set returnVal = CellNyUngdomFaelles
Case 7
Set returnVal = CellNyEnfasede
Case 8
Set returnVal = 0
Case 9
Set returnVal = CellNyLevOver25A
Case 10
Set returnVal = CellNyPrKW
Case 11
Set returnVal = CellNyFremtid
End Select
Set PickValue = returnVal
End Function[/vba]
Can anyone see where my problem is?
Thanks
-
Set is used for objects, not for primitives, so you need to replace
Set PickValue = returnVal
With
PickValue = returnVal
-
Ahh I see.
It worked perfectly.
Thank you very much
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules