Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Problems with "Get the Number(s) Out of a Cell..." (new TeachExcel UDF)

0

Hi Dan

Really like your macros and tips- very thought provoking and educational- thanks.

You just posted code for the UDF in the title but am I doing something wrong perhaps?

The UDF has a range as the input parameter "rCell" (via "Function GETNUMBER(rCell As Range, Optional Take_decimal As Boolean, Optional Take_negative As Boolean) As Double") but I had to change the command "sText = rCell" to "sText = rCell.Value" to get it to work at all.

I thought VBA generally took the value as a default so was a bit surprised. I'm using Excel 2013.

Anyone else have that problem?

John

Answer
Discuss

Answers

0

Hmm, well I'm in Excel 2010 and everything worked fine for me.

I copied/pasted the code into a module and then used the funciton like this:

=GETNUMBER(A1)

Not sure what the issue could be on your end.

Discuss

Discussion

Thanks Don

Apologies for wasting your time but I tried it again in a new Excel 2013 workbook and it worked fine this time. Think the problem might have been that yesterday I edtited the code before using (indenting so I could better understand Ifs and loops); suspect I introduced an error of some sort.

I find the way the switches operate currently doesn't suit me but (when I get a break at work) I'll use the code as the basis of an extrraction UDF. That or in a VBA sub to split text and numbers into cells).  Thanks for providing the impetus!

John  
John_R (rep: 9) Aug 25, '16 at 3:31 am
No worries! And sorry about the indentation, some of the older stuff on here, like that macro, lost the spacing it once had. When I get the new system for uploading macros finished all spacing should be maintained in future macros and tutorials.
don (rep: 1989) Aug 25, '16 at 11:59 am
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login