#1   Report Post  
ananga
 
Posts: n/a
Default Inserting zero

In excel suppose I have 6Y,2M,3D &6Y,10M,10D &10Y,2M,9D in three different
cell.If I will perform sort on these data in ascending /descending order it
doesn't come properly ,but if I will insert one zero to the left of each
single digit figure it is coming properly i.e. 6Y,2M,3D becomes 06Y,02M,03D
and 6Y,10M,10D becomes 06Y,10M,10D . Hence I want to know how can I insert
zero to each single digit figure by using functions or any other way so that
my large data can be sorted automatically.Because If I will inser zero to
each figure including double digit/three digit then also there will be a
mess.

Thanx .
  #2   Report Post  
bj
 
Posts: n/a
Default

try something like
=if(len(A1)=2,"0"&A1,A1)

"ananga" wrote:

In excel suppose I have 6Y,2M,3D &6Y,10M,10D &10Y,2M,9D in three different
cell.If I will perform sort on these data in ascending /descending order it
doesn't come properly ,but if I will insert one zero to the left of each
single digit figure it is coming properly i.e. 6Y,2M,3D becomes 06Y,02M,03D
and 6Y,10M,10D becomes 06Y,10M,10D . Hence I want to know how can I insert
zero to each single digit figure by using functions or any other way so that
my large data can be sorted automatically.Because If I will inser zero to
each figure including double digit/three digit then also there will be a
mess.

Thanx .

  #3   Report Post  
Dave Peterson
 
Posts: n/a
Default

I'd use a UserDefinedFunction that did the manipulation:

Option Explicit
Function AddZerosYMD(str As String) As String

Dim mySplit As Variant
Dim iCtr As Long
Dim tempStr As String

mySplit = Split97(str, ",")

tempStr = ""
For iCtr = LBound(mySplit) To UBound(mySplit)
tempStr = tempStr & "," & Right("0" & mySplit(iCtr), 3)
Next iCtr

AddZerosYMD = Mid(tempStr, 2)

End Function
Function Split97(sStr As String, sdelim As String) As Variant
'from Tom Ogilvy
Split97 = Evaluate("{""" & _
Application.Substitute(sStr, sdelim, """,""") & """}")
End Function

Split was added in xl2k. If you're using xl97, use Tom's split97. If you and
your users are all at xl2k or higher, you can delete that function
completely--and just use:

mysplit = split(str,",")

===
If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Short course:

Open your workbook.
Hit alt-f11 to get to the VBE (where macros/UDF's live)
hit ctrl-R to view the project explorer
Find your workbook.
should look like: VBAProject (yourfilename.xls)

right click on the project name
Insert, then Module
You should see the code window pop up on the right hand side

Paste the code in there.

Now go back to excel.
Into a test cell and type:
=addzerosymd(A1)



ananga wrote:

In excel suppose I have 6Y,2M,3D &6Y,10M,10D &10Y,2M,9D in three different
cell.If I will perform sort on these data in ascending /descending order it
doesn't come properly ,but if I will insert one zero to the left of each
single digit figure it is coming properly i.e. 6Y,2M,3D becomes 06Y,02M,03D
and 6Y,10M,10D becomes 06Y,10M,10D . Hence I want to know how can I insert
zero to each single digit figure by using functions or any other way so that
my large data can be sorted automatically.Because If I will inser zero to
each figure including double digit/three digit then also there will be a
mess.

Thanx .


--

Dave Peterson
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
inserting specific # of rows cwinters Excel Discussion (Misc queries) 1 June 6th 05 07:30 PM
How can I prevent Excel 2000 from inserting hyperlinks? RJL Jr. Setting up and Configuration of Excel 1 May 20th 05 12:15 PM
Excel Limitation - Inserting Colums - Help Tim Harding Excel Discussion (Misc queries) 1 April 29th 05 01:12 PM
inserting rows through external data source [email protected] Excel Discussion (Misc queries) 0 April 5th 05 03:16 AM
Inserting Footer - Ajit Ajit Munj Excel Discussion (Misc queries) 2 March 11th 05 02:39 PM


All times are GMT +1. The time now is 04:36 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"