Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Convert Percent Entered as Text in Wksht to Number in VBA

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,393
Default Convert Percent Entered as Text in Wksht to Number in VBA

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" wrote in message
...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,393
Default Convert Percent Entered as Text in Wksht to Number in VBA

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" wrote in message
...
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



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Convert Percent Entered as Text in Wksht to Number in VBA

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" wrote in message
...
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" wrote in message
...
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





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,393
Default Convert Percent Entered as Text in Wksht to Number in VBA

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" wrote in message
...
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" wrote in message
...
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" wrote in message
...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Look up number entered into text box and populate another with res Les Excel Programming 3 September 5th 08 04:51 AM
Need to display a number when a specific text is entered Desperate Excel Discussion (Misc queries) 3 December 31st 07 05:03 AM
How do I convert a percent number, for example, 12.34%, to text? joeZy Excel Worksheet Functions 1 May 4th 07 09:01 PM
Formatting a number to look like a Percent without a percent sign David Iacoponi Excel Discussion (Misc queries) 2 September 15th 05 06:35 PM
Entered text value equals a number I specify in another cell Dave S. Excel Worksheet Functions 3 June 12th 05 10:07 PM


All times are GMT +1. The time now is 10:10 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"