ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Mismatch!? (https://www.excelbanter.com/excel-programming/271404-mismatch.html)

Bob[_21_]

Mismatch!?
 
I've written this procedure below with some help and it
seems to work but I keep being informed of a type mismatch
on the line "If JData < 0..." Can anyone tell me why this
is happening? Also can anyone recommend a good code book
for referencing VBA on Excel 2000. I already have a text
book by Walkenbach but it doesn't have enough examples in
it.
Thanks, Bob

Private Sub CommandButton3_Click()
Dim JValue As Integer
Dim KValue As Integer
Dim LValue As Integer
Dim JData As Variant
Dim KData As Variant
Dim LData As Variant
Dim Data As Range
For i = 8 To 50
Set Data = Range("J" & i & ":O" & i)
JData = Range("J" & i)
KData = Range("K" & i)
LData = Range("L" & i)

If JData < 0 Then JValue = 0
If JData 0 Then JValue = 1


If KData < 0 Then KValue = 0
If KData 0 Then KValue = 1


If LData < 0 Then LValue = 0
If LData 0 Then LValue = 1


If JValue + KValue + LValue = 2 Then
Data.Font.ColorIndex = 5
End If

If JValue + KValue + LValue < 2 Then
Data.Font.ColorIndex = 10
End If
Next i
End Sub

Tom Ogilvy

Mismatch!?
 
If using xl2000 or later, you shouldn't have a problem. If you are using
xl97, it will give this error if jdata doesn't contain a numeric value when
you do the comparison. I believe a blank cell can cause it as well, but
don't have xl97 handy to test it. So you would need to test if jdata is
numeric or not.

Regards,
Tom Ogilvy



"Bob" wrote in message
...
I've written this procedure below with some help and it
seems to work but I keep being informed of a type mismatch
on the line "If JData < 0..." Can anyone tell me why this
is happening? Also can anyone recommend a good code book
for referencing VBA on Excel 2000. I already have a text
book by Walkenbach but it doesn't have enough examples in
it.
Thanks, Bob

Private Sub CommandButton3_Click()
Dim JValue As Integer
Dim KValue As Integer
Dim LValue As Integer
Dim JData As Variant
Dim KData As Variant
Dim LData As Variant
Dim Data As Range
For i = 8 To 50
Set Data = Range("J" & i & ":O" & i)
JData = Range("J" & i)
KData = Range("K" & i)
LData = Range("L" & i)

If JData < 0 Then JValue = 0
If JData 0 Then JValue = 1


If KData < 0 Then KValue = 0
If KData 0 Then KValue = 1


If LData < 0 Then LValue = 0
If LData 0 Then LValue = 1


If JValue + KValue + LValue = 2 Then
Data.Font.ColorIndex = 5
End If

If JValue + KValue + LValue < 2 Then
Data.Font.ColorIndex = 10
End If
Next i
End Sub





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

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