+ Reply to Thread
Results 1 to 8 of 8

Substring extraction without "Text to Columns"

Hybrid View

  1. #1
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Question Substring extraction without "Text to Columns"

    Hi all,
    I am unsure how to manipulate substrings without performing "text to columns".
    Background:
    Our sheet looks for and extracts data from a source based on unique identifiers. At times, the source will change the unique identifiers. Eg: v123456 may change to v654321. I have created some code that performs a cansim number validation check. If the number exists, continue with the update process. If it does not exist, the code will reference the title that corresponds to the cansim number. Eg: v654321 represents "Copper Prices" (the title). If the title is found from the source file, I want to update our cansim number to match the source cansim number. The problem is, the source cansim number is embedded in the source title. Eg: Title "Copper Prices [1003] (v654321)", which is located in one cell. I want to extract just the "v" series number (v654321) and not the rest. How can I extract just the "v" series?
    Hopefully I have described this well enough.

    Best Regards:
    Last edited by Mordred; 10-01-2010 at 06:14 PM.
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  2. #2
    Forum Expert
    Join Date
    07-16-2010
    Location
    Northumberland, UK
    MS-Off Ver
    Excel 2007 (home), Excel 2010 (work)
    Posts
    3,054

    Re: Substring extraction without "Text to Columns"

    Is the v-number always in brackets?

    If so try:

    =MID(A1,FIND("(",A1)+1,LEN(A1)-(FIND("(",A1)+1))

  3. #3
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Substring extraction without "Text to Columns"

    Hi Andrew, thanks for your input. Yes, the v-numbers is always in brackets from the source. I tried what you suggested but it creates a compile error stating "A1" variable cannot be defined. Is your suggestion a function for the spreadsheet side of things? I'll be completely honest, I am not very well versed with the spreadsheet side, I've taken on Excel programmatically, not the other way around. Anyhow, here is the code I am trying to apply this to:

    For Each Cell In Application.Workbooks("IndustryPriceIndexCopy.xls").Worksheets("Mthly").Range("Cansim")
        For iCount = 1 To Windows(fName).Application.Sheets.Count
            Set CansimCell = Application.Workbooks(fName).Sheets(iCount).Cells.Find(Cell)
            If CansimCell Is Nothing Then
                Set CansimCell = Application.Workbooks(fName).Sheets(iCount).Cells.Find(Cell.Offset(0, -2))
                If Not CansimCell Is Nothing Then
                    Cell.Value =       :confused:'''''''This is where the value needs to change, if need be!'''''':confused:
                    MsgBox Cell.Value
                End If
            End If
        Next iCount
    Next Cell

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,229

    Re: Substring extraction without "Text to Columns"

    If the number you want always has the ( and ) characters around it then it is pretty simple.

    If "Copper Prices [1003] (v654321)" is in B3 then the formula to extract stuff between ( and ) is:

    =MID(B3,FIND("(",B3)+1,FIND(")",B3) - FIND("(",B3)-1)

    Other guys like to replace all the stuff to the left of ( with "" and start from there.
    You will need to find the formula that you like the best.

  5. #5
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Substring extraction without "Text to Columns"

    I see the confused emoticon does not work when inside code tags.

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Substring extraction without "Text to Columns"

    on error resume next
    For Each Cell In Workbooks("IndustryPriceIndexCopy.xls").Worksheets("Mthly").Range("Cansim")
        For j = 1 To Windows(fName).Application.Sheets.Count
          if not Workbooks(fName).Sheets(iCount).Cells.Find(Cell) is noting then msgbox= split(Workbooks(fName).Sheets(iCount).Cells.Find(Cell.Offset(0, -2)),"(v")(1)
        Next 
    Next



  7. #7
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,229

    Re: Substring extraction without "Text to Columns"

    Hi Mordred,
    You can extract the v654321 number using VBA string functions. There are a lot less of them than in Excel. Find the list at: http://www.techonthenet.com/excel/fo.../index_vba.php
    This site shows how to convert cell functions to VBA.

    If you need help extracting the string between ( and ) using vba please reply to this and I'll do it.

  8. #8
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Substring extraction without "Text to Columns"

    Thanks Marvin for the link, I used this and it works:

    If Not CansimCell Is Nothing Then
    Cell.Value = Right(CansimCell, 10)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1