IF THEN ELSE in VBA

C

CCManager

What I am trying to do:
If the user has cell M3 selected, then change cell S8 to show the dat
in cell K57. If the user has cell M5 selected, change cell S8 to sho
the data in cell K58...and so on.

Here is what I have that is not working.

Sub FieldTip()
If ActiveCell.Value = ("M3") Then Range("S8").Value = ("K57")
Else: If ActiveCell.Value = ("M5") Then Range("S8").Value = ("K58")
Else: Range("S8").Value = " "
End If
End Sub

Any help would be greatly appreciated
 
N

Norman Jones

Hi CCManager,

Try:

Sub FieldTip2()
With Range("B1")

If ActiveCell.Address(0, 0) = "M3" Then
.Value = Range("K57").Value
ElseIf ActiveCell.Address(0, 0) = "M5" Then
.Value = Range("K58").Value
Else
.Value = ""
End If
End With
End Sub
 
J

JE McGimpsey

One way:

Public Sub FieldTip()
Select Case ActiveCell.Address(False, False)
Case "M3"
Range("S8").Value = Range("K57").Value
Case "M5"
Range("S8").Value = Range("K58").Value
Case Else
Range("S8").ClearContents
End Select
End Sub

Note: Change

Range("S8").ClearContents

to

Range("S8").Value = " "

if you really want the space character inserted.
 
T

Tom Ogilvy

Sub FieldTip()
If ActiveCell.Address = "$M$3" Then
Range("S8").Value = Range("K57").Value
ElseIf ActiveCell.Addess = "$M$5") Then
Range("S8").Value = Range("K58").Value
Else
Range("S8").Value = " "
End If
End Sub

How many cells does "so on" refer to?
 
C

CCManager

Sorry so long since replied but another project took precedence over
this one and just now able to get back to work on it.

The "and so on" refers to a total of 8 cell matches that must be made.

Also I have tried all your suggestions thusfar and for some reason none
of them are producing a result in cell S8. Could merged cells cause a
conflict in this?

Thanks again for all of your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top