Thread: Replace Macro
View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.misc
Sandy Mann Sandy Mann is offline
external usenet poster
 
Posts: 2,345
Default Replace Macro

Using XL97.

If I enter 8:00 in A1, (formatted as h:mm), and then record a macro to
select A1 and replace a space with nothing, XL rightly tells me that if
cannot find any matching data to replace. However, if I then run the macro
that was recorded, (below), it changes the entry in A1 to 8:00:00AM ie it
removes the space between the 00 and the AM as if the entry had been 8:00:00
AM

Two questions:
1. I thought that formatting was just a mask over the *real* data in the
cell which is what is displayed in General format. If that is the case then
A1 would have held 0.33333333333333, so why does the VBA Replace find a
space? I suppose that the *Replace* in VBA is not the same *Replace* as the
one on the Edit menu but surely the data is 0.33333333333333 not a text
8:00:00 AM.

Sub Macro1()
Range("A1").Select
Cells.Replace What:=" ", Replacement:="", LookAt:=xlPart, SearchOrder:=
_
xlByRows, MatchCase:=False
End Sub

(I know that if I change it to LookAt:=xlWhole then it will not replace the
space but I can't understand how it happens in VBA but not manually.)

2. Does this just happen in XL97 or all versions?

--
Regards,

Sandy
In Perth, the ancient capital of Scotland
and the crowning place of kings


Replace @mailinator.com with @tiscali.co.uk