+ Reply to Thread
Results 1 to 3 of 3

Excel (2010) Macro to extract string between semi colons

Hybrid View

  1. #1
    Registered User
    Join Date
    01-10-2011
    Location
    Netherlands
    MS-Off Ver
    Excel 2010
    Posts
    3

    Excel (2010) Macro to extract string between semi colons

    Hi,

    I am trying to build a macro that extracts a string between semi colons. For example,

    Record no. 2551: Unknown combination of numbers. (#40: : BT12345678) (;BT12345678;0)

    I would need to extract the string BT12345678 which is between the two semi colons and copy that to the cell next to it.There are many rows of this type down the document, though the needed string is not always in same place (but always between the two semi colons). This macro should run for all the lines till the end of the document. I hope somebody can help me.

    Thanks.

  2. #2
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Excel (2010) Macro to extract string between semi colons

    try
    Sub ert()
    Dim x, i&
    'On Error Resume Next
    With Range("A1", Cells(Rows.Count, 1).End(xlUp))
        x = .Value
        For i = 1 To UBound(x)
            x(i, 1) = Split(x(i, 1), ";")(1)
        Next i
        .Offset(, 1).Value = x
    End With
    End Sub

  3. #3
    Forum Contributor
    Join Date
    06-07-2012
    Location
    London, England
    MS-Off Ver
    Excel 2010
    Posts
    189

    Re: Excel (2010) Macro to extract string between semi colons

    Try

    Sub atest()
    Dim LR As Long, i As Long
    LR = Range("A" & Rows.Count).End(xlUp).Row
    For i = 1 To LR
        With Range("A" & i)
            .Offset(, 1).Value = Mid(.Value, InStr(.Value, ";") + 1, InStrRev(.Value, ";") - InStr(.Value, ";") - 1)
        End With
    Next i
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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