Question:
Function not returning value in EXCEL VBA?
Clinton
2013-01-31 05:55:58 UTC
I am trying to write a function which will give me the number value of a column in Excel.

The column letter is from using the worksheet_change event from the Target reference and passed into another procedure.

The code to call the function is
Dim columntouse As Integer
columntouse = ConvertColumnToInt(firstcolumn)

(Firstcolumn is one of the procedure parameters passed)

The function code is:
Public Function ConvertColumnToInt(columnstring As String) As Integer

Dim OutputNumber As Integer
Dim Leng As Integer
Dim i As Integer


Leng = Len(columnstring)
OutputNumber = 0


For i = 1 To Leng
OutputNumber = (Asc(UCase(Mid(columnstring, i, 1))) - 64) + OutputNumber * 26
Next i

End Function

However, the value in "columntouse" remains at zero; how do I get the result from the function to pass into it?
Three answers:
Jonathan
2013-01-31 07:55:24 UTC
It's been a while since I've coded in VBA, but I believe you need to have a line similar to



ConvertColumnToInt = OutputNumber



at the end of your function. This works similar to a return statement in other languages, and tells the function what value to pass back.
?
2017-01-05 18:12:38 UTC
Vba Function Return Value
osuch
2016-12-11 15:09:03 UTC
Your carry out is decrease out and are not waiting to make certain something after For command, any mindset you additionally could have have been given to characteristic this line shippingday = your result which you're able to desire to flow returned ensure the call is a similar perceive as you declared the perform above in function Shippingday() make certain the letters, not extra, no much less by the form, why you're able to desire to try this once you're able to do it making use of geared up in applications. i will do the carry out blend to precisely such as you're able to desire to do. must you love mail me added documents, and that i will probable be happy to help examine my profile, i'm XLMan


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...