View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
Gary''s Student Gary''s Student is offline
external usenet poster
 
Posts: 11,058
Default Find and Replace is going wrong in some cases

If column S contains:

1
3
2
1
4
0
1
3
2
0
2
4
2
1
3
1
4
1
0
4
1
0
2
0
0
4
3
4
2
3
4
1
1
4
2
1
1
1
3
1

then running:

Sub serviant()

Dim r As Range
Set r = Range("S:S")

r.Replace What:="0", Replacement:="ASSET", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, _
ReplaceFormat:=False
Columns("S:S").AutoFit



r.Replace What:="1", Replacement:="C.ASSET", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, _
ReplaceFormat:=False


r.Replace What:="2", Replacement:="F.ASSET", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, _
ReplaceFormat:=False



r.Replace What:="3", Replacement:="LIABLITIES", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, _
ReplaceFormat:=False


r.Replace What:="4", Replacement:="C.LIABLITIES", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, _
ReplaceFormat:=False

End Sub

will produce:

C.ASSET
LIABLITIES
F.ASSET
C.ASSET
C.LIABLITIES
ASSET
C.ASSET
LIABLITIES
F.ASSET
ASSET
F.ASSET
C.LIABLITIES
F.ASSET
C.ASSET
LIABLITIES
C.ASSET
C.LIABLITIES
C.ASSET
ASSET
C.LIABLITIES
C.ASSET
ASSET
F.ASSET
ASSET
ASSET
C.LIABLITIES
LIABLITIES
C.LIABLITIES
F.ASSET
LIABLITIES
C.LIABLITIES
C.ASSET
C.ASSET
C.LIABLITIES
F.ASSET
C.ASSET
C.ASSET
C.ASSET
LIABLITIES
C.ASSET

--
Gary''s Student - gsnu200854


"pol" wrote:


Selection.Replace What:="4", Replacement:="C.LIABLITIES", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, _
ReplaceFormat:=False

When I am giving the above condion at the end of the following replace
statement , the result is showing wrongly. Please anybody can suggest a good
openion for this.


Columns("S:S").Select
Range("S1").Activate

Selection.Replace What:="0", Replacement:="ASSET", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, _
ReplaceFormat:=False
Columns("S:S").AutoFit



Selection.Replace What:="1", Replacement:="C.ASSET", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, _
ReplaceFormat:=False


Selection.Replace What:="2", Replacement:="F.ASSET", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, _
ReplaceFormat:=False



Selection.Replace What:="3", Replacement:="LIABLITIES", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=True, SearchFormat:=False, _
ReplaceFormat:=False

With Regards
Pol