Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Help with UserForm Code

I want to check the value that the user has entered by comparing to a lookup
table called 'CWTable'

Below is the code.
My problems:
- If I define CheckWeightMIN & MAX as integers, I get a type mismatch error
at the VLOOKUP step (note I remove .value in the IF statement if I use
integer)
-If I define CheckWeightMIN & MAX as variants, then I get a type mismatch at
the line IF CheckWeight...
- If I add .value as seen below, I get a error 424.

Help!!
Thanks.

Mark
-----------------------
'Check for Crazy Weight
Dim CrazyWeight As Boolean
CrazyWeight = False
Dim CheckWeight As Integer
Dim CheckWeightMIN As Variant
Dim CheckWeightMAX As Variant
Dim CheckAge As Integer
Dim Response

If Optkg = "True" Then
CheckWeight = PtWeightBox.Value
Else
CheckWeight = PtWeightBox.Value / 2.2
End If
If OptYears = "True" Then
CheckAge = PtAgeBox.Value
Else
CheckAge = PtAgeBox.Value / 12
End If

CheckWeightMIN = Application.VLookup(CheckAge, "CWTable", 2, True)
CheckWeightMAX = Application.VLookup(CheckAge, "CWTable", 3, True)

If CheckWeight CheckWeightMAX.Value Or CheckWeight < heckWeightMIN.Value
Then
CrazyWeight = True
End If

If CrazyWeight = True Then
Response = MsgBox("You have entered a weight of " & CheckWeight & "kg
for your " & CheckAge & " year old patient. This weight is out of range. Is
this correct? Click Cancel to re-enter", vbOKCancel, CrazyWeight)
If Response = "Cancel" Then
Exit Sub
Else
CrazyWeight = False
End If
End If
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Help with UserForm Code

"CWTable" is a string. To make it a range that can be Lookin, it need to
be'

Range("CWTable")

ex:
Dim CheckWeight As Long
' vlookup can return and error so these should be variant
Dim CheckWeightMIN As Variant
Dim CheckWeightMAX As Variant

Dim CheckAge As Long

CheckWeightMIN = Application.VLookup(CheckAge, Range("CWTable"), 2, True)
CheckWeightMAX = Application.VLookup(CheckAge, Range("CWTable"), 3, True)

if iserror(CheckWeightMin) or iserror(CheckWeightMax) then
msgbox "Problems looking for value"
exit sub
End if



typo he
CheckWeight < heckWeightMIN.Value

--
Regards,
Tom Ogilvy



"sneagle" wrote in message
...
I want to check the value that the user has entered by comparing to a

lookup
table called 'CWTable'

Below is the code.
My problems:
- If I define CheckWeightMIN & MAX as integers, I get a type mismatch

error
at the VLOOKUP step (note I remove .value in the IF statement if I use
integer)
-If I define CheckWeightMIN & MAX as variants, then I get a type mismatch

at
the line IF CheckWeight...
- If I add .value as seen below, I get a error 424.

Help!!
Thanks.

Mark
-----------------------
'Check for Crazy Weight
Dim CrazyWeight As Boolean
CrazyWeight = False
Dim CheckWeight As Integer
Dim CheckWeightMIN As Variant
Dim CheckWeightMAX As Variant
Dim CheckAge As Integer
Dim Response

If Optkg = "True" Then
CheckWeight = PtWeightBox.Value
Else
CheckWeight = PtWeightBox.Value / 2.2
End If
If OptYears = "True" Then
CheckAge = PtAgeBox.Value
Else
CheckAge = PtAgeBox.Value / 12
End If

CheckWeightMIN = Application.VLookup(CheckAge, "CWTable", 2, True)
CheckWeightMAX = Application.VLookup(CheckAge, "CWTable", 3, True)

If CheckWeight CheckWeightMAX.Value Or CheckWeight < heckWeightMIN.Value
Then
CrazyWeight = True
End If

If CrazyWeight = True Then
Response = MsgBox("You have entered a weight of " & CheckWeight & "kg
for your " & CheckAge & " year old patient. This weight is out of range.

Is
this correct? Click Cancel to re-enter", vbOKCancel, CrazyWeight)
If Response = "Cancel" Then
Exit Sub
Else
CrazyWeight = False
End If
End If



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
Creating a Userform using code trini Excel Programming 1 March 5th 05 11:15 PM
Userform Code scrabtree23[_3_] Excel Programming 3 December 5th 04 05:05 AM
Have userform & reams of code! Mark \(InWales\)[_10_] Excel Programming 3 October 27th 04 07:30 AM
UserForm code help needed. madbloke[_6_] Excel Programming 4 September 17th 04 04:12 PM
VBA code for Userform Martin Los Excel Programming 4 December 5th 03 03:04 PM


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

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"