+ Reply to Thread
Results 1 to 7 of 7

Remove symbols from numbers

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    03-16-2004
    MS-Off Ver
    2016
    Posts
    175

    Remove symbols from numbers

    Please open the workbook for reference. Looking for a macro that will look at sheet 1 Col G. Am only concerned with the far right number in that column’s cells. Some are plain, some have asterisks, some have parenthesis around them. Need to ignore all those items and just look at the number and pair it to the name in same row in col D. Also do not want the number that appears before the name in Col D. I want the names ranked according to the value of Col G far right. The names are usually in chronological order to Col G’s far right value. But there are ties. Output should look like Sheet2.

    The other data I am interested in is in Col M. I want to focus the first number in those cells in that column. Those are not in chronological order but I want the names ranked with their value as seen on sheet 2. They never have extraneous symbols attached to them as the previous section I mentioned. Length of names columns varies from 4 to 30.

    Sorry for the title
    Attached Files Attached Files
    Last edited by light; 12-07-2019 at 08:03 PM.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2509 (Windows 11 Home 24H2 64-bit)
    Posts
    92,591

    Re: Extract

    Administrative Note:

    We would very much like to help you with your query, however the thread title does not really convey what your request is about.

    Please take a moment to amend your thread title. Make sure that the title properly explains your request. Your title should be explicit and not be generic (this includes function names used without an indication of what you are trying to achieve).

    Please see Forum Rule #1 about proper thread titles and adjust accordingly. To edit the thread title, open the original post to edit and then click on Go Advanced (bottom right) to access the area where you can edit your title.

    (Note: this change is not optional. No help to be offered until this moderation request has been fulfilled.)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,491

    Re: Extract

    Quote Originally Posted by light View Post
    The names are usually in chronological order to Col G’s far right value.
    For the first part of your request... your use of the word "usually" is troublesome. Please clarify... are the names always in the correct order as listed or would we have to sort them the make sure they are in the correct order?

  4. #4
    Forum Contributor
    Join Date
    03-16-2004
    MS-Off Ver
    2016
    Posts
    175

    Remove symbols from numbers

    I said "usually" because there are ties as well.

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,835

    Re: Remove symbols from numbers

    Sub test()
        Dim a, i As Long
        Application.ScreenUpdating = False
        With Sheets("sheet1")
            With .Range("d6", .Range("d" & Rows.Count).End(xlUp)).Resize(, 10)
               a = Application.Index(.Value, Evaluate("row(1:" & .Rows.Count & ")"), [{1,4,1,1,1,10}])
            End With
        End With
        With CreateObject("VBScript.RegExp")
            For i = 1 To UBound(a, 1)
                a(i, 3) = Empty: a(i, 4) = Empty
                .Pattern = "^\d+ (.+?) *\d.*"
                If .test(a(i, 1)) Then
                    a(i, 1) = .Replace(a(i, 1), "$1")
                    a(i, 5) = a(i, 1)
                End If
                .Pattern = "\b\d+(?=\D*$)"
                If .test(a(i, 2)) Then a(i, 2) = Val(.Execute(a(i, 2))(0))
                .Pattern = "^\d+\b"
                If .test(a(i, 6)) Then a(i, 6) = Val(.Execute(a(i, 6))(0))
            Next
        End With
        With Sheets("sheet2").[d6].Resize(UBound(a, 1), UBound(a, 2))
            .Resize(, .Columns.Count + 1).EntireColumn.Clear
            .Value = a
            With .Columns(3)
                .Formula = "=rank(" & .Cells(1, 0).Address(0, 0) & "," & .Columns(0).Address & ",0)"
                .Value = .Value
                .Cut .Columns(0)
            End With
            With .Columns("e:f")
                .Sort .Cells(1, 2), 2
                .Columns(3).Formula = "=sumproduct((" & .Cells(1, 2).Address(0, 0) & "<=" & .Columns(2).Address & _
                    ")/countif(" & .Columns(2).Address & "," & .Columns(2).Address & "))"
                .Offset(, 1).Font.Bold = True
            End With
        End With
        Application.ScreenUpdating = True
    End Sub
    Attached Files Attached Files

  6. #6
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,491

    Re: Remove symbols from numbers

    Here is another macro that you can consider...
    Sub RankNames()
      Dim LastRow As Long, WS1 As Worksheet, WS2 As Worksheet
      Set WS1 = Sheets("Sheet1")
      Set WS2 = Sheets("Sheet2")
      LastRow = WS1.Cells(Rows.Count, "D").End(xlUp).Row
      WS2.Range("D6:J" & LastRow).ClearContents
      With WS2.Range("D6:D" & LastRow)
        .Value = Evaluate(Replace( Replace("IF({1},MID(LEFT('@'!#,FIND(""  "",'@'!#)-1),FIND("" "",'@'!#)+1,99))", "@", WS1.Name), "#", .Address))
        .Copy .Offset(, 4)
        .Offset(, 1).Value = Evaluate("IF({1},SUBSTITUTE(SUBSTITUTE('" & WS1.Name & "'!" & .Offset(, 3).Address & ","")"",""""),""*"",""""))")
        .Offset(, 1).Replace "* ", "", xlPart, , , , False, False
        .Offset(, 1).Value = Evaluate(Replace( Replace("IF({1},RANK('@'!#,'@'!#))", "@", WS2.Name), "#", .Offset(, 1).Address))
        .Offset(, 5).Value = Evaluate(Replace( Replace("IF({1},LEFT('@'!#,FIND("" "",'@'!#)-1))", "@", WS1.Name), "#", .Offset(, 9).Address))
        .Offset(, 4).Resize(, 2).Sort WS2.Columns("I"), xlDescending
        .Offset(, 6).Formula = "=IF(I5<>I6,J5+1,J5)"
        .Offset(, 6).Value = .Offset(, 6).Value
      End With
    End Sub

  7. #7
    Forum Contributor
    Join Date
    03-16-2004
    MS-Off Ver
    2016
    Posts
    175

    Re: Remove symbols from numbers

    Wow! I think it would have taken me another lifetime to have figured it out. Thanks jindon and Rick.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Extract First Name
    By Chivers in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 03-17-2017, 04:08 AM
  2. [SOLVED] How to Extract Extract on userform
    By tariqjahangir in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-05-2016, 04:28 PM
  3. Replies: 3
    Last Post: 12-18-2014, 10:27 AM
  4. Extract all data to new workbook then filter and extract to new worksheets
    By graphicgoose in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-04-2014, 08:18 PM
  5. How can I extract each Max key value ?
    By diglas1 via OfficeKB.com in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 05-31-2006, 06:10 PM
  6. Extract Unique Values, Then Extract Again to Remove Suffixes
    By Karl Burrows in forum Excel General
    Replies: 23
    Last Post: 06-25-2005, 08:05 PM

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