0

I have written the following code:

Function Find_Index(Gender As String)

   Dim Index As Long

   Do While Gender = Worksheets("Source").Cells(Index, "A").Text

       Index = Index + 1

   Loop

   Find_Index = Index

End Function

I'm getting the following error:

"Application-defined or object-defined error"

Due to the following line in the code:

Do While Gender = Worksheets("Source").Cells(Index, "A").Text

Any ideas why ?

1 Answer 1

3

You define Index but never set it to a value before you use it.

Add Index = 1 before the Do While line

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

1 Comment

I cannot believe I missed that. Thank you very much!

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.