Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA question - Percentages in text box

Hi

I need to input data in percentage format, like this: 50.5%

Which code can I use? I also want to prevent user of inputing wron
data.

Private Sub PercentTB_KeyPress(ByVal KeyAscii A
MSForms.ReturnInteger)
If ((KeyAscii < Asc("0")) Or (KeyAscii Asc("9"))) Then
If (KeyAscii < 0) Or (KeyAscii 1) Then
KeyAscii = 0
End If
End If
'MsgBox PercentTB.Value
End Su

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default VBA question - Percentages in text box

Private Sub PercentTB_Exit(ByVal Cancel As MSForms.ReturnBoolean)
PercentTB.Text = Format(csng(PercentTB.Text),"#0.#%)
End Sub

Private Sub PercentTB_KeyPress(ByVal KeyAscii As _
MSForms.ReturnInteger)
If KeyAscii < Asc("0") Or KeyAscii Asc("9") Then
if KeyAscii < asc(Application.international( _
xlDecimalSeparator)) then ' allow decimal separator
KeyAscii = 0
End If
End If
'MsgBox PercentTB.Value
End Sub

Not sure what values you want to allow. Will they enter a percent or a
decimal?

--
Regards,
Tom Ogilvy




"ajliaks " wrote in message
...
Hi

I need to input data in percentage format, like this: 50.5%

Which code can I use? I also want to prevent user of inputing wrong
data.

Private Sub PercentTB_KeyPress(ByVal KeyAscii As
MSForms.ReturnInteger)
If ((KeyAscii < Asc("0")) Or (KeyAscii Asc("9"))) Then
If (KeyAscii < 0) Or (KeyAscii 1) Then
KeyAscii = 0
End If
End If
'MsgBox PercentTB.Value
End Sub


---
Message posted from http://www.ExcelForum.com/



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
Text function question. DP7 Excel Worksheet Functions 2 October 3rd 07 06:21 PM
Pivot Table Question: Show percentages and standard number format TimT Excel Discussion (Misc queries) 0 October 26th 06 03:14 PM
Text to Columns Question Dennis Excel Worksheet Functions 8 December 30th 05 12:52 PM
Text box question Greg B... Excel Discussion (Misc queries) 0 March 1st 05 07:28 AM
Text box question Greg B... Excel Discussion (Misc queries) 3 February 27th 05 02:47 PM


All times are GMT +1. The time now is 04:46 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"