#1   Report Post  
Posted to microsoft.public.excel.misc
Daminc
 
Posts: n/a
Default Sorting error


I copy and paste numerical order numbers from the web onto a spreadsheet
and sort them.

I usually use a Macro to do this but recently the numbers don't sort
properly anymore.

It seems like some of these numbers are actually text but even after I
format the cells to 'Number' they still do not sort.

I believe I've copied over some format or other with the number but
even copy / paste special values doesn't seem to help.

Can anyone tell me what the score is here.

Below is an example of the numbers I'm trying to sort:


90721
90728
90731
90826
90851
90872
1002894
90709
90738
90851
90878
90903


--
Daminc
------------------------------------------------------------------------
Daminc's Profile: http://www.excelforum.com/member.php...o&userid=27074
View this thread: http://www.excelforum.com/showthread...hreadid=530501

  #2   Report Post  
Posted to microsoft.public.excel.misc
Chip Pearson
 
Posts: n/a
Default Sorting error

Try the following to convert text to number. Enter 1 in some
empty cell and copy it. Then select your range of data. Go to the
Edit menu, choose Paste Special and select the Multiply
operation. Click OK.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Daminc"
wrote in message
...

I copy and paste numerical order numbers from the web onto a
spreadsheet
and sort them.

I usually use a Macro to do this but recently the numbers don't
sort
properly anymore.

It seems like some of these numbers are actually text but even
after I
format the cells to 'Number' they still do not sort.

I believe I've copied over some format or other with the number
but
even copy / paste special values doesn't seem to help.

Can anyone tell me what the score is here.

Below is an example of the numbers I'm trying to sort:


90721
90728
90731
90826
90851
90872
1002894
90709
90738
90851
90878
90903


--
Daminc
------------------------------------------------------------------------
Daminc's Profile:
http://www.excelforum.com/member.php...o&userid=27074
View this thread:
http://www.excelforum.com/showthread...hreadid=530501



  #3   Report Post  
Posted to microsoft.public.excel.misc
Daminc
 
Posts: n/a
Default Sorting error


I found this:


Code:
--------------------
Sub ConvertToNumbers()
Cells.SpecialCells(xlCellTypeLastCell) _
.Offset(1, 1).Copy
Selection.PasteSpecial Paste:=xlPasteValues, _
Operation:=xlPasteSpecialOperationAdd
With Selection
.VerticalAlignment = xlTop
.WrapText = False
End With
Selection.EntireColumn.AutoFit
End Sub
--------------------


which seems like it clears it up but I don't know why.

Any advice?


--
Daminc
------------------------------------------------------------------------
Daminc's Profile: http://www.excelforum.com/member.php...o&userid=27074
View this thread: http://www.excelforum.com/showthread...hreadid=530501

  #4   Report Post  
Posted to microsoft.public.excel.misc
Daminc
 
Posts: n/a
Default Sorting error


Hi Chip, thanks for the advice.

your solution worked. For me to use it in a macro I'll have to put in
the value 1 in a cell somewhere and then clear it after the
transformation has been completed.

After looking at your solution the one I posted makes a little more
sense but it failed (my one) when I tried to run it a second time which
is odd.


--
Daminc
------------------------------------------------------------------------
Daminc's Profile: http://www.excelforum.com/member.php...o&userid=27074
View this thread: http://www.excelforum.com/showthread...hreadid=530501

  #5   Report Post  
Posted to microsoft.public.excel.misc
Daminc
 
Posts: n/a
Default Sorting error


I thought I'd put in the completed solution here in case it might help
someone else:



Code:
--------------------
Sub find_duplicates()
'
' find_duplicates Macro
' Macro recorded 07/07/2005 by PreeceJ
'

'
Application.Run "'Validation sheet.xls'!sort_for_duplicates"
Range("K1").Select
Application.Run "'Validation sheet.xls'!FindDups"
End Sub



Sub sort_for_duplicates()
'
' sort_for_duplicates Macro
' Macro recorded 07/07/2005 by PreeceJ
'

Range("K:K").Select
With Selection
.HorizontalAlignment = xlGeneral
.VerticalAlignment = xlBottom
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = False
End With
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = False
End With
Selection.Sort Key1:=Range("K1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

Range("'Validation sheet.xls'!saleID").Select

'The saleID range I've put in as a dynamic range on the excel sheet
'InsertNameDefine
'Type in the name of the range (in this case saleID)
'In the box "Refers to" type in
' =OFFSET(worksheetname!$K$1,0,0,COUNTA(worksheetnam e!$K$1:$K$65),1)
'(change the name and range to suit your needs)

Application.Run "'Validation sheet.xls'!ConvertToNumbers"

Selection.Sort Key1:=Range("K1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

End Sub


Sub ConvertToNumbers()

Range("n1") = 1
Range("n1").Copy
Selection.PasteSpecial Paste:=xlAll, Operation:=xlMultiply, SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
Range("n1") = ""
With Selection
.VerticalAlignment = xlTop
.WrapText = False
End With

End Sub


Sub FindDups()
'
' NOTE: You must select the first cell in the column and
' make sure that the column is sorted before running this macro
'
ScreenUpdating = False
FirstItem = ActiveCell.Value
SecondItem = ActiveCell.Offset(1, 0).Value
Offsetcount = 1
Do While ActiveCell < ""
If FirstItem = SecondItem Then
ActiveCell.Offset(Offsetcount, 0).Interior.Color = RGB(255, 0, 0)
Offsetcount = Offsetcount + 1
SecondItem = ActiveCell.Offset(Offsetcount, 0).Value
Else
ActiveCell.Offset(Offsetcount, 0).Select
FirstItem = ActiveCell.Value
SecondItem = ActiveCell.Offset(1, 0).Value
Offsetcount = 1
End If
Loop
ScreenUpdating = True
End Sub
--------------------


hope this helps ;)


--
Daminc
------------------------------------------------------------------------
Daminc's Profile: http://www.excelforum.com/member.php...o&userid=27074
View this thread: http://www.excelforum.com/showthread...hreadid=530501



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Formula Problem - interrupted by #VALUE! in other cells!? Ted Excel Worksheet Functions 17 November 25th 05 05:18 PM
XL - Oracle connection Error parthi4u Excel Discussion (Misc queries) 0 September 14th 05 08:45 PM
Problem Opening an Excel File MSO9.DLL Error Mash23 Links and Linking in Excel 0 August 24th 05 03:21 PM
SQL Server ODBC Error Art Saffran Excel Discussion (Misc queries) 0 March 24th 05 02:37 PM
ERROR Pinto1uk Excel Discussion (Misc queries) 1 February 8th 05 03:15 AM


All times are GMT +1. The time now is 09:29 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"