Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default IF THEN ELSE in VBA

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

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default IF THEN ELSE in VBA

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


---
Regards,
Norman

"CCManager " wrote in message
...
What I am trying to do:
If the user has cell M3 selected, then change cell S8 to show the data
in cell K57. If the user has cell M5 selected, change cell S8 to show
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.


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default IF THEN ELSE in VBA

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.

In article ,
CCManager wrote:

What I am trying to do:
If the user has cell M3 selected, then change cell S8 to show the data
in cell K57. If the user has cell M5 selected, change cell S8 to show
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.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default IF THEN ELSE in VBA

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?



--
Regards,
Tom Ogilvy


"CCManager " wrote in message
...
What I am trying to do:
If the user has cell M3 selected, then change cell S8 to show the data
in cell K57. If the user has cell M5 selected, change cell S8 to show
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.


---
Message posted from http://www.ExcelForum.com/



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default IF THEN ELSE in VBA

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.


---
Message posted from http://www.ExcelForum.com/

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



All times are GMT +1. The time now is 09:55 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"