View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rob van Gelder[_4_] Rob van Gelder[_4_] is offline
external usenet poster
 
Posts: 1,236
Default display values in cell

You've got the structure right, but are struggling with the Range object.

I figure you'll be able to get it going with your If, ElseIf routine, but
thought I'd demonstrate another way:

Sub test()
Dim rng1 As Range, rng2 As Range

Set rng1 = Range("A1")
Set rng2 = Range("B1")

Select Case rng1.Value
Case Is < 90: rng2.Value = "OK"
Case Is 100: rng2.Value = "Overdue"
Case Else: rng2.Value = "Notice"
End Select
End Sub


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"tim" wrote in message
...
I am new to Excel VBA but quite comfortable with Access
VBA.

I would like to enter a value in cell C1 based on the
following conditions

If the value in A1 is < 90 then display OK in B1
If the value in A1 is 100 display Overdue in B1
If the value in A1 is between 90 and 100 print Notice in
B1

This is what I have but it is not working

Private Sub Worksheet_SelectionChange(ByVal Target As
Range)

Dim celA1 As Integer
Dim celB1 As String

celA1 = Range("A1:A1")
celB1 = Range("B1:B1")


If celA1 < 90 Then
celB1 = "OK"
ElseIf celA1 100 Then
celB1 = "Overdue"
Else
celB1 = "Notice"
End If



End Sub

Thanks for any help