Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default How to extract all numbers preceded by a dash

We get data in a report that is indecipherable. I need to extract all switch numbers following a "$" that preceed a "-1".
for example from the following output I need the following results. Note that each long string is contained in one cell.

Output Results
$1$2$3$4$5$6$7$8$9$10$11$25$50$51$52$99 null

$1-1$2$3$4$5$6$7$8$9$10$11$12$13$14$15$16$25$26$27$28 $30$31$32$33$50$51$52$53$54$55$60$61$80$85$97$98$9 9 1

$1$2$3$4$5$6$7$8$9$10$11$12$13$14$15$16$25$26$27$2 8$30-1$31-1$32$33$40$50$51$52-1$53$54$55$60$61$70$80$85-1$97$98$99 30,31,52,85

$1$2$3$4$5$6$7$8$9$10$11$12$13$14$15$25$26$27$28$3 0-1$31-1$32$50$51$52$53$54$55$80$85$97$98-1$99-1 30,31,98,99

$1$2$3$4$5$6$7$8$9$10$11$12$13$14$15$16$25$26$27$2 8$30-1$31-1$32$33$40$50-1$51$52$53$54-1$55$60$61$70$80$85-1$97$98$99-1 30,31,50,54,85,99

$1$2$3$4$5$6$7$8$9$10$11$12$13$14$15$16$25$26$27$2 8$30-1$31-1$32$33$40-1$50$51$52$53$54$55$60$61$70$80$85$97$98$99-1 30,31,40,99

$1$2$3$4$5$6$7$8$9$10$11$12$13$14$15$16$25$26$27$2 8$30-1$31-1$32$33$40$50$51$52$53$54$55$60$61$70$80$85$97$98-1$99-1 30,31,98,99

$1$2$3$4$5$6$7$8$9$10$11$12$13$14$15$16$25$26$27$2 8$30-1$31-1$32$33$40$50$51$52$53$54$55$60$61$70$80$85$97$98-1$99-1 30,31,98,99
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How to extract all numbers preceded by a dash

On Friday, February 20, 2015 at 12:47:40 PM UTC-5, Claus Busch wrote:
Hi,

Am Fri, 20 Feb 2015 09:18:07 -0800 (PST) schrieb :

We get data in a report that is indecipherable. I need to extract all switch numbers following a "$" that preceed a "-1".
for example from the following output I need the following results. Note that each long string is contained in one cell.


try it with an UDF:

Function myString(myRng As Range) As String
Dim varData As Variant
Dim i As Long, Start As Long

varData = Split(myRng, "-1")
If UBound(varData) = 0 Then
myString = "Null"
Else
For i = 0 To UBound(varData) - 1
Start = InStrRev(varData(i), "$") + 1
myString = myString & Mid(varData(i), Start) & ", "
Next
End If
If myString < "Null" Then
myString = Left(myString, Len(myString) - 2)
End If
End Function

If your data in in column A then call the function with
=myString(A1)
and copy down


Regards
Claus B.
--
Vista Ultimate / Windows7
Office 2007 Ultimate / 2010 Professional


Fantastic, Claus! You hit it out of the ballpark! Many thanks!
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 587
Default How to extract all numbers preceded by a dash

hi,

Function MySplit(rng As Range) As String
x = Split(rng, "$")
For i = LBound(x) To UBound(x)
If Not IsError(Application.Find("-", x(i))) Then r = r & Split(x(i), "-")(0) & " "
Next
MySplit = r
End Function

isabelle

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How to extract all numbers preceded by a dash

On Friday, February 20, 2015 at 1:11:47 PM UTC-5, isabelle wrote:
hi,

Function MySplit(rng As Range) As String
x = Split(rng, "$")
For i = LBound(x) To UBound(x)
If Not IsError(Application.Find("-", x(i))) Then r = r & Split(x(i), "-")(0) & " "
Next
MySplit = r
End Function

isabelle


Thanks Isabelle, that gets it done as well!
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
Adding a dash to phone numbers Jim Excel Discussion (Misc queries) 2 December 19th 08 07:50 PM
Extract number between a dash Eric Excel Discussion (Misc queries) 3 January 24th 08 12:37 AM
inserting a dash into a column of numbers pm Excel Worksheet Functions 6 November 8th 06 09:51 PM
Count comma separated numbers, numbers in a range with dash, not t Mahendra Excel Discussion (Misc queries) 0 August 8th 05 05:56 PM


All times are GMT +1. The time now is 05:39 AM.

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"