Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Error control dont work!

Hi

I have a userform with a textbox on it.

On loading it picks up a number from a cell on the spreadsheet. I want
a % sign in the textbox with the number, ie 15%. I use the following
code to achieve that.

UserForm6.TextBox5.Value = Format(Sheets("Rate
Table").Range("f4").Value, "###,##0.00""%")

When the user edits the textbox and press Enter the infomation is the
checked to make sure its a number and the entered back into the
spreadsheet. I use the following code to achieve that.

If IsNumeric(UserForm6.TextBox5.Text) & "%" = False Then GoTo
errorhandler:

ActiveCell.Offset(0, 5).Value =
Application.Substitute(UserForm6.TextBox5.Value, "%", "")

My problem is if the textbox is left blank or a letter is entered, it
does not error. Infact i dont think the error code works at all.

Please advise, i have run out of idea's

Thanks


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Error control dont work!

I'd load the userform with something like:

with worksheets("Rate table").range("F4")
if isnumeric(.value) then
me.textbox5.value = format(.value,"###,##0.00%")
'or if the cell is already formatted
'me.textbox5.value = .text
else
me.textbox5.value = "Invalid???"
end if
end with

And dump the userform with something like:

Dim myVal As Variant
Dim myStr As String
Dim FoundPct As Boolean

FoundPct = False
myStr = Me.TextBox5.Value
If Right(myStr, 1) = "%" Then
FoundPct = True
myStr = Left(myStr, Len(myStr) - 1)
End If

On Error Resume Next
myVal = CDbl(myStr)
If Err.Number < 0 Then
'not numeric
Err.Clear
myVal = "Invalid"
Else
If FoundPct Then
myVal = myVal / 100
End If
End If

MsgBox = myVal 'or plop it into a cell


Adam wrote:

Hi

I have a userform with a textbox on it.

On loading it picks up a number from a cell on the spreadsheet. I want
a % sign in the textbox with the number, ie 15%. I use the following
code to achieve that.

UserForm6.TextBox5.Value = Format(Sheets("Rate
Table").Range("f4").Value, "###,##0.00""%")

When the user edits the textbox and press Enter the infomation is the
checked to make sure its a number and the entered back into the
spreadsheet. I use the following code to achieve that.

If IsNumeric(UserForm6.TextBox5.Text) & "%" = False Then GoTo
errorhandler:

ActiveCell.Offset(0, 5).Value =
Application.Substitute(UserForm6.TextBox5.Value, "%", "")

My problem is if the textbox is left blank or a letter is entered, it
does not error. Infact i dont think the error code works at all.

Please advise, i have run out of idea's

Thanks


--

Dave Peterson
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
flash object dont work in my excel work sheet Nitn Excel Discussion (Misc queries) 0 July 4th 09 08:00 AM
i dont know what file to name when registering Calender Control Kess Excel Discussion (Misc queries) 1 December 17th 07 09:24 AM
Formulas dont work comotoman Excel Discussion (Misc queries) 4 October 3rd 05 06:48 PM
Error Control no work :( CodeSponge[_2_] Excel Programming 5 January 12th 05 09:47 PM
Error control no work :( CodeSponge[_2_] Excel Programming 1 January 12th 05 04:00 PM


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

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

About Us

"It's about Microsoft Excel"