View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Ron Rosenfeld Ron Rosenfeld is offline
external usenet poster
 
Posts: 5,651
Default bug in excel 2007 for sorting function?

On Thu, 23 Apr 2009 04:13:01 -0700, javamama
wrote:

Hi, I believe there is a bug in excel 2007 for sorting function. I have a
worksheet with the first column being a building code. Some of the codes
consist of a number only(such as 1001), and some with a number and a
letter(such as 1001a). my intent was to be able to sort these codes
numerically, such as 1001, 1001a, 2000, etc. I painted down the column and
did a format, format cells, text. Then tried to sort. excel put the numbers
with letters after all the pure numbers, even though I attempted to format
all the cells as text. I was able to find a work around: I inserted 2
columns to the left of my building code column. In the first column, I
inserted the formula "=type(C1)". this column returned some type 1's
(number) and some type 2's (text) even after I had painted down the column
and formatted all the cells as text. Then I painted the building code column
down and formated as number, then input "=text(C1,0)" in the 2nd column,
which forced all the building codes to be type text. Then I was able to sort
numerically. The point is that excel should have made all the building
codes text when I painted down the column and did a format, format cells,
text, but it didn't. Have you had other reports of this problem?


I am assuming you changed the cell format after entering the data.

Changing the format of a cell does not necessarily change the type of data
already stored within the cell. Formatting as text will ensure that any NEW
data entered into the cell will take on the Text attribute, however.

One way to convert already entered data to TEXT, so it will sort as you wish,
is with a VBA macro.

To enter this Macro (Sub), <alt-F11 opens the Visual Basic Editor.
Ensure your project is highlighted in the Project Explorer window.
Then, from the top menu, select Insert/Module and
paste the code below into the window that opens.

To use this Macro (Sub), <alt-F8 opens the macro dialog box. Select the macro
by name, and <RUN.

======================================
Option Explicit
Sub NumToText()
Dim c As Range
For Each c In Selection
With c
.NumberFormat = "@"
.Value = .Text
End With
Next c
End Sub
==========================
--ron