ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   vba error (https://www.excelbanter.com/excel-discussion-misc-queries/137435-vba-error.html)

hazel

vba error
 
Hi All

This has to be easy for all you experts out there -- a userform with 2 text
boxes
entering a number or a zero in Tb2 the following code runs OK on running
the macro. leave it blank and the debugger kicks in is there a way round this
problem.
probably a msg telling them to enter a zero??

ws.Cells(iRow, 10).Value = Val(Trim(Me.Tb1.Value * 0.5)) +
Val(Trim(Me.Tb2.Value * 0.05))

--
Many thanks

hazel

Dave Peterson

vba error
 
I'd check to make sure that the values in the textboxes were numeric before I
tried to place the new value in the cell:

if isnumeric(me.tb1.value) _
and isnumeric(me.tb2.value) then
ws.cells(irow, ....
else
msgbox "please enter numbers"
end if


Hazel wrote:

Hi All

This has to be easy for all you experts out there -- a userform with 2 text
boxes
entering a number or a zero in Tb2 the following code runs OK on running
the macro. leave it blank and the debugger kicks in is there a way round this
problem.
probably a msg telling them to enter a zero??

ws.Cells(iRow, 10).Value = Val(Trim(Me.Tb1.Value * 0.5)) +
Val(Trim(Me.Tb2.Value * 0.05))

--
Many thanks

hazel


--

Dave Peterson

Toppers

vba error
 
try:

ws.Cells(iRow, 10).Value = Val(Me.Tb1.Value) * 0.5 +
Val(Me.Tb2.Value) * 0.05

"Hazel" wrote:

Hi All

This has to be easy for all you experts out there -- a userform with 2 text
boxes
entering a number or a zero in Tb2 the following code runs OK on running
the macro. leave it blank and the debugger kicks in is there a way round this
problem.
probably a msg telling them to enter a zero??

ws.Cells(iRow, 10).Value = Val(Trim(Me.Tb1.Value * 0.5)) +
Val(Trim(Me.Tb2.Value * 0.05))

--
Many thanks

hazel


hazel

vba error
 
Hi To you both

Thanks you both turned up trumps, now works whatever the person enters in
the text boxes providing it is numeric -- no entry, macro runs on its merry
sweet way.and still finishes the job.
--
Many thanks

hazel


"Dave Peterson" wrote:

I'd check to make sure that the values in the textboxes were numeric before I
tried to place the new value in the cell:

if isnumeric(me.tb1.value) _
and isnumeric(me.tb2.value) then
ws.cells(irow, ....
else
msgbox "please enter numbers"
end if


Hazel wrote:

Hi All

This has to be easy for all you experts out there -- a userform with 2 text
boxes
entering a number or a zero in Tb2 the following code runs OK on running
the macro. leave it blank and the debugger kicks in is there a way round this
problem.
probably a msg telling them to enter a zero??

ws.Cells(iRow, 10).Value = Val(Trim(Me.Tb1.Value * 0.5)) +
Val(Trim(Me.Tb2.Value * 0.05))

--
Many thanks

hazel


--

Dave Peterson



All times are GMT +1. The time now is 09:45 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com