Wrox Programmer Forums
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

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
 
Old November 8th, 2006, 04:06 PM
Authorized User
 
Join Date: Nov 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default user function attempt

Am a novice with advanced VBA.

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.

Anyone help me out here? - regards dennis


 
Old November 8th, 2006, 04:16 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Hey Dennis,

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.

Mike

Mike
EchoVue.com
 
Old November 8th, 2006, 05:36 PM
Authorized User
 
Join Date: Nov 2006
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Mike, works a treat. I was hoping the answer might be as simple as that.

regards dennis

 
Old November 8th, 2006, 05:59 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

No Worries Dennis, Nice easy problems, but then you don't know whether to kick yourself, or just be relieved.

Welcome to the forum - you'll find it an invaluable resource as you get more into VBA.

Mike

Mike
EchoVue.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
Go for View or User Defined function vinod_yadav1919 SQL Server 2000 1 December 12th, 2007 05:18 AM
Search Function and User Controls hpox BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 3 January 8th, 2007 11:00 AM
Search Function and User Controls hpox ASP.NET 2.0 Professional 0 December 22nd, 2006 02:27 PM
Calling User Defined Function penta Access 5 March 4th, 2005 12:57 PM
User Defined Function niravp SQL Server 2000 7 November 29th, 2004 02:18 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.