You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
I am trying to establish the column number for a cell via a user defined function. My ultimate aim is to establish offset values of named cells in row 1 of particular sheet. These values make a columnar list on another sheet.
Public Function GetCol(R As Range) As Long
Dim x
x = R.Column
End Function
From within the sheet, and calling this function returns 0, although the function does calculate the correct value.
VBA is sneaky with this. Rather than a return value, what you want to do is set GetCol to the value you want to return. Add a line with GetCol = x and you should be good to go. Or you could just remove x from the function entirely.