PC Review


Reply
Thread Tools Rate Thread

Convert Percent Entered as Text in Wksht to Number in VBA

 
 
Keith Young
Guest
Posts: n/a
 
      16th Oct 2008
This should be easy but am having a very difficult time.

The percent 10.00% is entered exactly as this in a worksheet cell as text.
What VBA function will convert to a number? Thought Val or CDbl would do it
but both generate an error (Type Mismatch)

Msgbox Val(Sheet1.Range("A1").value)
Msgbox CDbl(Sheet1.Range("A1").value)

Thanks in advance for your help. Keith


 
Reply With Quote
 
 
 
 
Bernard Liengme
Guest
Posts: n/a
 
      16th Oct 2008
Either of these formulas will do the trick: (a) =VALUE(A1), (b) =--A1

--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"Keith Young" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> This should be easy but am having a very difficult time.
>
> The percent 10.00% is entered exactly as this in a worksheet cell as text.
> What VBA function will convert to a number? Thought Val or CDbl would do
> it but both generate an error (Type Mismatch)
>
> Msgbox Val(Sheet1.Range("A1").value)
> Msgbox CDbl(Sheet1.Range("A1").value)
>
> Thanks in advance for your help. Keith
>



 
Reply With Quote
 
Bernard Liengme
Guest
Posts: n/a
 
      16th Oct 2008
If VBA must be used

Sub trythis()
Set d = Range("A1")
perval = Val(Mid(d, 1, Len(d) - 1)) / 100
MsgBox perval
End Sub

best wishes
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"Keith Young" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> This should be easy but am having a very difficult time.
>
> The percent 10.00% is entered exactly as this in a worksheet cell as text.
> What VBA function will convert to a number? Thought Val or CDbl would do
> it but both generate an error (Type Mismatch)
>
> Msgbox Val(Sheet1.Range("A1").value)
> Msgbox CDbl(Sheet1.Range("A1").value)
>
> Thanks in advance for your help. Keith
>



 
Reply With Quote
 
Keith Young
Guest
Posts: n/a
 
      16th Oct 2008
yes, that is what I needed. Thank you very much

Strange that the worksheet function Value will convert it but the VBA
function Val will not.


"Bernard Liengme" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> If VBA must be used
>
> Sub trythis()
> Set d = Range("A1")
> perval = Val(Mid(d, 1, Len(d) - 1)) / 100
> MsgBox perval
> End Sub
>
> best wishes
> --
> Bernard V Liengme
> Microsoft Excel MVP
> http://people.stfx.ca/bliengme
> remove caps from email
>
> "Keith Young" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> This should be easy but am having a very difficult time.
>>
>> The percent 10.00% is entered exactly as this in a worksheet cell as
>> text. What VBA function will convert to a number? Thought Val or CDbl
>> would do it but both generate an error (Type Mismatch)
>>
>> Msgbox Val(Sheet1.Range("A1").value)
>> Msgbox CDbl(Sheet1.Range("A1").value)
>>
>> Thanks in advance for your help. Keith
>>

>
>



 
Reply With Quote
 
Bernard Liengme
Guest
Posts: n/a
 
      16th Oct 2008
The big problem is that VBA knows nothing about % as a way to indicate a
value is to be treated as being divided by 100
all the best
--
Bernard V Liengme
Microsoft Excel MVP
http://people.stfx.ca/bliengme
remove caps from email

"Keith Young" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> yes, that is what I needed. Thank you very much
>
> Strange that the worksheet function Value will convert it but the VBA
> function Val will not.
>
>
> "Bernard Liengme" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> If VBA must be used
>>
>> Sub trythis()
>> Set d = Range("A1")
>> perval = Val(Mid(d, 1, Len(d) - 1)) / 100
>> MsgBox perval
>> End Sub
>>
>> best wishes
>> --
>> Bernard V Liengme
>> Microsoft Excel MVP
>> http://people.stfx.ca/bliengme
>> remove caps from email
>>
>> "Keith Young" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>>> This should be easy but am having a very difficult time.
>>>
>>> The percent 10.00% is entered exactly as this in a worksheet cell as
>>> text. What VBA function will convert to a number? Thought Val or CDbl
>>> would do it but both generate an error (Type Mismatch)
>>>
>>> Msgbox Val(Sheet1.Range("A1").value)
>>> Msgbox CDbl(Sheet1.Range("A1").value)
>>>
>>> Thanks in advance for your help. Keith
>>>

>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I convert a percent number, for example, 12.34%, to text? =?Utf-8?B?am9lWnk=?= Microsoft Excel Worksheet Functions 1 4th May 2007 09:01 PM
Convert Decimal to Percent Within Text String Brian Microsoft Excel Discussion 4 22nd Nov 2006 05:41 PM
How do I convert text entered in a form into normal text? =?Utf-8?B?QW5keU1vbGw=?= Microsoft Word Document Management 3 1st Sep 2006 05:42 PM
Percent showing hundreds instead of actual percent number =?Utf-8?B?SnVkeVQ=?= Microsoft Access Reports 1 27th Apr 2006 03:27 PM
How to convert dates entered as text to values Michael Microsoft Excel Worksheet Functions 8 9th Jun 2004 04:57 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:13 AM.