LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #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
 
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 10:25 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"