Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default insert a dash

I have a column of numbers, 5 digit up to 9 digit. I need to insert a dash
after the first number of any 5 digit number, and a dash after the second
digit if the number is longer than 5 digits.

so 12345 would need to become 1-2345
and 1234567 would need to become 12-34567

If my original numbers are in column A, I can make the new ones in Column B

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default insert a dash

Give this formula a try...

=REPLACE(A1,3-(LEN(A1)=5),0,"-")

--
Rick (MVP - Excel)



"Striker3070" wrote in message
...
I have a column of numbers, 5 digit up to 9 digit. I need to insert a
dash after the first number of any 5 digit number, and a dash after the
second digit if the number is longer than 5 digits.

so 12345 would need to become 1-2345
and 1234567 would need to become 12-34567

If my original numbers are in column A, I can make the new ones in Column
B


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default insert a dash

And if you were looking for a VB solution, consider looping your cells using
a statement construction similar to this...

DashedText = Application.Replace(CellText, 3 + (LEN(CellText)=5),0,"-")

--
Rick (MVP - Excel)



"Rick Rothstein" wrote in message
...
Give this formula a try...

=REPLACE(A1,3-(LEN(A1)=5),0,"-")

--
Rick (MVP - Excel)



"Striker3070" wrote in message
...
I have a column of numbers, 5 digit up to 9 digit. I need to insert a
dash after the first number of any 5 digit number, and a dash after the
second digit if the number is longer than 5 digits.

so 12345 would need to become 1-2345
and 1234567 would need to become 12-34567

If my original numbers are in column A, I can make the new ones in Column
B


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 126
Default insert a dash

=if(len(a1)<=5,left(A1,1)&"-"&right(a1,len(a1)-1)
,left(a1,2)&"-"&right(a1,len(a1)-2))
--
Hope this helps.
If it does, please click the Yes button.
Thanks in advance for your feedback.
Gary Brown



"Striker3070" wrote:

I have a column of numbers, 5 digit up to 9 digit. I need to insert a dash
after the first number of any 5 digit number, and a dash after the second
digit if the number is longer than 5 digits.

so 12345 would need to become 1-2345
and 1234567 would need to become 12-34567

If my original numbers are in column A, I can make the new ones in Column B

.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 320
Default insert a dash

You can also just format the cells:
[<100000]0-0000;00-00000

"Striker3070" wrote:

I have a column of numbers, 5 digit up to 9 digit. I need to insert a dash
after the first number of any 5 digit number, and a dash after the second
digit if the number is longer than 5 digits.

so 12345 would need to become 1-2345
and 1234567 would need to become 12-34567

If my original numbers are in column A, I can make the new ones in Column B

.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,942
Default insert a dash

hi
since you posted in programming, perhaps a VB solution.....
Sub insertdash()
Dim r As Range, c As Range
Set r = Range("A2:A" & Cells(Rows.Count, "A").End(xlUp).Row)
For Each c In r
If Len(c) 5 Then
c.Value = Left(c, 2) & "-" & Right(c, Len(c) - 2)
Else
c.NumberFormat = "@" 'in case xl can interpret as a date
c.Value = Left(c, 1) & "-" & Right(c, Len(c) - 1)
End If
Next c
End Sub

regards
FSt1

"Striker3070" wrote:

I have a column of numbers, 5 digit up to 9 digit. I need to insert a dash
after the first number of any 5 digit number, and a dash after the second
digit if the number is longer than 5 digits.

so 12345 would need to become 1-2345
and 1234567 would need to become 12-34567

If my original numbers are in column A, I can make the new ones in Column B

.

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
If I have a list of numbers, how do I insert a dash in each one? rayofsunshine969 Excel Discussion (Misc queries) 2 November 18th 09 07:43 PM
How insert a dash in the third position of a column with data? warren Excel Discussion (Misc queries) 1 July 19th 06 09:42 PM
insert a dash acp20770 Excel Programming 2 December 7th 05 03:56 PM
Need insert a dash in between last 4 digits in text string Phil Excel Worksheet Functions 3 August 22nd 05 10:48 PM
Shortcut Key to insert an em-dash? Fred Holmes Excel Programming 1 May 23rd 05 06:43 PM


All times are GMT +1. The time now is 05:49 PM.

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

About Us

"It's about Microsoft Excel"