View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Tachyon Tachyon is offline
external usenet poster
 
Posts: 4
Default Problem with Subs and If's !

Thanks Ryan - great help. Learning at light speed here :-)
--
Tachyon


"RyanH" wrote:

The second If...Then Statement is what is causing the macro to continuely
loop to infinite. The default property for ranges is .Value. Plus, you need
to clean up your code a bit, like this:

Private Sub Worksheet_Change(ByVal Target As Range)

Application.EnableEvents = False

On Error GoTo ErrorHandler
If Target = "GD" Then
Range("B1") = "Graeme John Dixon"
Else
Range("B1") = "I don't know you"
End If

ErrorHandler:
Application.EnableEvents = True

End Sub

for your second if then statement I would recommend putting that in formula
bar in Cell B5, like this

= IF(B5="Graeme John Dixon","Test", "")

Hope this is helpful. If so please give credit.
--
Cheers,
Ryan


"Tachyon" wrote:

Hi - Ok, I'm a real newbie so this will be easy for someone :-)

I can't figure why this code loops around in strange ways and doesn't just
step through doing the If's and Then's etc. I'll say no more at this stage
because it's probably embarassingly blindingly obvious to everyone else!

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Value = "GD" Then
Selection.Range("B1").Value = ("Graeme John Dixon")
Else
Selection.Range("B1").Value = ("I don't know you")
End If
If Range("B5").Value = ("Graeme John Dixon") Then
Range("A1") = ("Test")
End If
End Sub

--
Tachyon