View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Nasser Hosseini Nasser Hosseini is offline
external usenet poster
 
Posts: 1
Default Selection.Replace doesn't update the cell value in macro!

Hi everyone,
I'm trying to read a text file containg data like this
5.55
5.57
5.98
5.63
5.82
into Excel 2000, replacing the "." by ",", and calcualting the mean
value in the following macro sequence:

....
Dim theRange As Range

Range("A1:A5").Select
Selection.Replace What:=".", Replacement:=",", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False
Set theRange = Selection
Range("B1").Value = Application.WorksheetFunction.Average(theRange)
....

I get the run time error 1004 'Could not find Average property for
Worksheet function class'. The problem is probably that after
selection.replace, the cell values aren't correctly updated. Doing this
manually in the worksheet doesn't cause any problem and runs just fine!!!

Any comments, solutions???

Thanks in advance

/Nasser Hosseini