View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Tushar Mehta Tushar Mehta is offline
external usenet poster
 
Posts: 1,071
Default ElseIf Statement problem

From what I can tell your code is doing exactly what it is programmed
to do!

Assuming that AB25 contains something other than N and AB23 contains N,
M50 will contain Jerry.

The Find method is searching for Alternate not for Jerry as in
Selection.Find(What:="Alternate",...

So, there is no reason to expect it will find Jerry.

The Replace method is replacing Alternate with Jerry.
ActiveCell.Replace What:="Alternate", Replacement:="Jerry",...

The code is doing exactly what it is programmed to do. It might not be
your intent but that is another story.

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article <59419c86a8634@uwe, u13156@uwe says...
I have set a condition :

Range("M50").Select
If Range("AB25").Value = "N" Then
ActiveCell = "Drew"
ElseIf Range("AB23").Value = "N" Then
ActiveCell = "Jerry"
Else: ActiveCell = "Alternate"
End If

After this condition, Jerry is put into cell M50 because AB25's value is not
"N"

I then have a condition following this that states:

Range("M5,M38,M44,M50,M57,M63,M69,M74,M79,M85").Se lect
If Range("AB23").Value = "N" And Range("M38,M44,M50,M57,M63,M69,M74,
M79,M85").Value < "Jerry" Then
On Error Resume Next
Selection.Find(What:="Alternate", LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Replace What:="Alternate", Replacement:="Jerry", LookAt:
=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End If

My problem lies within the ElseIf statement because when the Selection.Find
runs, it does not see "Jerry" in cell M50 and ends up finding a cell with the
word "Alternate" in it, replacing it with Jerry so my end result is having
two cells with "Jerry" in them.

Help! I have no idea where my problem lies.