I am trying to learn excel vba and i am having an issue with a value not being returned from a function.
I have a spreadsheet and i look for data in it , in a specific column, from a specific line. I am trying to find the line that contains my data. When found, i want to return that line number to my main sub.
The function finds the data and the line number. MsgBox displays the right line number but my main sub does not seem to see it.
Below my simple function:
Function findLine()
Dim Line As Integer
Dim Output As Integer
Line = 4
mysh = "data"
Do Until Sheets(mysh).Range("B" & Line).Value = "found" And Sheets(mysh).Range("C" & Line).Value = "you"
Line = Line + 1
Loop
Output = Line
MsgBox Output ' this displays the right line number
End Function
and the call from my name :
myline = findLine()
Msgbox myline ' this shows an empty box.
Could you please advise about what i am doing wrong ?
cheers !