Thread: Paste numbers
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Sally Mae Sally Mae is offline
external usenet poster
 
Posts: 16
Default Paste numbers

Thanks Norman but the code just does not work. Also it takes a very long time
to run and it does not remove the blanks. I think it is better to use the
code that I got from recording the macro. The code is:

Private Sub findAndRemoveBlanks()
Cells.Select
Selection.Replace What:=" ", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End Sub

This code fixes the problem with the blanks but the other problem remains.
Please please please help me if you have any idea. I dont understand this and
it must be a fairly common problem since alot of people paste numbers into
Excel and the use these number for calculations. I am very thankful for any
help!


"Norman Jones" skrev:

Hi Sally,

Try:

'=============
Public Sub Tester()
Dim WB As Workbook
Dim SH As Worksheet
Dim rng, rCell As Range
Set WB = ActiveWorkbook
Set SH = WB.Sheets("Beräkning")
Set rng = SH.UsedRange
'Set rng = SH.Range("A1:p100")

For Each rCell In rng.Cells
With rCell
.Select
If Not IsEmpty(.Value) Then
If Not UCase(.Value) Like "*[A-Z]*" Then
.NumberFormat = "0.00"
.Replace What:=" ", Replacement:="", LookAt:=xlPart
End If
End If
End With
Next rCell

End Sub
'<<=============


---
Regards,
Norman



"Sally Mae" wrote in message
...
Hi Norman! Sorry for the confusion, a bit stressed. .It works like this:

OK It works like this.

1) The user copies info from a program a paste it onto the spreadsheet.
2) the user presses a button
3) the macro is executed and calculations are presented

My problem is that when I run my macro that includes the sub that find and
remove blanks, Excel cannot make calculations. When I check the Excel
spreadsheet I see that the cells that have been affected by the sub
findAndRemoveBlanks have a small green marking. When choosing this marking
with my mouse I see that these cells are stored as text (the is what excel
says when I right click on these cells). I can then choose to convert
these
cells into numbers. Thus I draw the conclusion that the macro somehow
affect
the format of the cells.

After the user has pasted the info into the spreadsheet the format of the
cells is General. After having run the macro the format has changed.

I have also tried this code (that works better but with the same problem):

Private Sub findAndRemoveBlanks()
Cells.Select
Selection.Replace What:=" ", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
end sub

please help me out if you know how to!