Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
tim tim is offline
external usenet poster
 
Posts: 105
Default display values in cell

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,885
Default display values in cell

Hi Tim
first why are you using VBA for this task. You can put the following
formula in B1
=IF(A1<"",IF(A1100,"OVERDUE",IF(A1<90,"OK","Noti ce")),"")

For your code example, try the following (if you really want to use the
worksheet change event):

Private Sub Worksheet_Change(ByVal Target As Range)
Dim b_rng as range
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("A1")) Is Nothing Then Exit Sub
Set b_rng = Range("B1")
On Error GoTo CleanUp:
With Target
if .value <"" then
Application.EnableEvents = False
If .Value 100 then
b_rng.value = "Overdue
elseif .value < 90 then
b_rng.value = "OK"
else
b_rng.value = "Notice"
end if
else
b_rng.value = ""
end if
End With
CleanUp:
Application.EnableEvents = True
End Sub



Frank


tim wrote:
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



  #4   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default display values in cell

Frank;

Thanks, I am using VBA because this would give me more
flexibility such as writing function, sub procedure.

My Access VBA background has skewed me towards this
direction.

Thanks again

Tim

I do know that I could do what you said but my Access VBA
-----Original Message-----
Hi Tim
first why are you using VBA for this task. You can put

the following
formula in B1
=IF(A1<"",IF(A1100,"OVERDUE",IF

(A1<90,"OK","Notice")),"")

For your code example, try the following (if you really

want to use the
worksheet change event):

Private Sub Worksheet_Change(ByVal Target As Range)
Dim b_rng as range
If Target.Cells.Count 1 Then Exit Sub
If Intersect(Target, Me.Range("A1")) Is Nothing Then

Exit Sub
Set b_rng = Range("B1")
On Error GoTo CleanUp:
With Target
if .value <"" then
Application.EnableEvents = False
If .Value 100 then
b_rng.value = "Overdue
elseif .value < 90 then
b_rng.value = "OK"
else
b_rng.value = "Notice"
end if
else
b_rng.value = ""
end if
End With
CleanUp:
Application.EnableEvents = True
End Sub



Frank


tim wrote:
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



.

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
I need to display changing cell values in another cell. anoviceuser Excel Worksheet Functions 2 October 30th 07 04:02 PM
How do I have a data table display cell names rather than values? raortiz99 Excel Worksheet Functions 1 November 9th 05 04:11 PM
display values in cell Vincent Excel Discussion (Misc queries) 2 February 21st 05 04:16 PM
display negative values as a blank cell in Excel Pheroze Bharucha Excel Discussion (Misc queries) 0 January 4th 05 10:51 PM
How to display cell values in wordarts? Anderson Lee Excel Discussion (Misc queries) 2 December 28th 04 03:05 PM


All times are GMT +1. The time now is 02:40 PM.

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"