0

I have a simple Function to get and save values in array:

Function GetDataOwner()

 Dim DataOwner(2) As String

 DataOwner(0) = Sheets(1).Range("H21").Value
 DataOwner(1) = Sheets(1).Range("I21").Value
 DataOwner(2) = Sheets(1).Range("J21").Value


End Function

In other function, I would like read value:

Sub GenerateDB()

  Dim DataOwner() As String
  DataOwner = GetDataOwner()

  MsgBox DataOwner(1)
End Sub

But Excel say me error 13 type mismatch. I am novice with VBA function

1
  • 2
    You need to return the array from the GetDataOwner function: GetDataOwner = DataOwner on the line above End Function Commented Oct 20, 2016 at 18:29

1 Answer 1

1

Soluce:

Function GetDataOwner()

 Dim DataOwner(2) As String

 DataOwner(0) = Sheets(1).Range("H21").Value
 DataOwner(1) = Sheets(1).Range("I21").Value
 DataOwner(2) = Sheets(1).Range("J21").Value

 GetDataOwner = DataOwner
End Function


Sub GenerateDB()

  Dim DataOwner() As String
  DataOwner = GetDataOwner()

  MsgBox DataOwner(1)
End Sub

Thanks to @Comintern

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.