beginner question: how to get text from a cell (1,234.00) insteadof value of cell (1,234)?

M

Mike Scirocco

I wrote a function that creates a code based on a numeric string inside
a cell. The function uses each digit of the cell text to calculate the
output, so the function returns a different number for 1,234.00 than it
does for 1,234.

I wrote the function then entered the function call in a cell so that
the value in the cell is a function of the text in another cell, but the
function never sees the .00, it always sees the value minus the .00.

How can I pass the text in cell to a fuction, not the numeric value in
the cell?

Here's the function call I place in a cell that uses the text in D41 as
an input:

=SumDigitsPlusLength(D41)

Here's the relevant bits of the function:

Public Function SumDigitsPlusLength(inputvalue as string) As String
'inputvalue is always the numeric value not the text from the cell
'e.g. the inputvalue string always contains "1,234", whether the
'cell contains the text "1,234.00" or "1,234".
...
End Function

Thank You,
Mike
 
M

Mike Scirocco

Mike said:
I wrote a function that creates a code based on a numeric string inside
a cell. The function uses each digit of the cell text to calculate the
output, so the function returns a different number for 1,234.00 than it
does for 1,234.

I wrote the function then entered the function call in a cell so that
the value in the cell is a function of the text in another cell, but the
function never sees the .00, it always sees the value minus the .00.

How can I pass the text in cell to a fuction, not the numeric value in
the cell?

Here's the function call I place in a cell that uses the text in D41 as
an input:

=SumDigitsPlusLength(D41)

Here's the relevant bits of the function:

Public Function SumDigitsPlusLength(inputvalue as string) As String
'inputvalue is always the numeric value not the text from the cell
'e.g. the inputvalue string always contains "1,234", whether the
'cell contains the text "1,234.00" or "1,234".
...
End Function

Thank You,
Mike

I found an approach using Google that works:

send the cell I want the text from to the function as a range, then in
the function declare a string variable, and assign the range.text to the
string variable... works great!

=SumDigitsPlusLength(D41)

Public Function SumDigitsPlusLength(rcell As Range) As String
Dim inputvalue As String
inputvalue = rcell.Text
...
End Function

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top