+ Reply to Thread
Results 1 to 6 of 6

Thread: Macro to Delete Spaces between text and numbers in a cell

  1. #1
    Registered User
    Join Date
    12-30-2011
    Location
    London, Ont
    MS-Off Ver
    Excel 2007
    Posts
    61

    Macro to Delete Spaces between text and numbers in a cell

    I have a worksheet with a column K populated with over 13000 lines of descriptions as this.. e.g

    BASKET PERF 254 X 254 X 30 MM
    SCISSOR CVDMAYO HARRINGTON 230 MM
    SCISSOR METZENBAUM CURVED 180 CM
    SCISSOR LATERAL ANGLE POTTS-SMITH 55DEGREE S/S 180 MM
    SCISSOR POTTS-DE-MARTEL 45 DEGREES STAINLESS/STEEL 185 CM


    I want to make them:

    BASKET PERF 254X254X30MM
    SCISSOR CVDMAYO HARRINGTON 230MM
    SCISSOR METZENBAUM CURVED 180CM
    SCISSOR LATERAL ANGLE POTTS-SMITH 55DEGREE S/S 180MM
    SCISSOR POTTS-DE-MARTEL 45 DEGREES STAINLESS/STEEL 185CM



    Just to delete the spaces between the numbers and the unit of Measure,..


    Can anyone help?

    Thanks in Advance.
    Last edited by bigdee008@yahoo.com; 01-23-2012 at 03:38 PM.

  2. #2
    Forum Contributor
    Join Date
    06-16-2011
    Location
    London
    MS-Off Ver
    Excel XP
    Posts
    189

    Re: Macro to Delete Spaces between text and numbers in a cell

    Will the unit of measure always be 2 characters? EDIT: This also depends on the unit of measure always being at the end of the line.

    If so....

    
    Dim ASweep integer
    Dim UM, UN as string
    
    For ASweep = 1 to Range("K65536").End(xlUp).Row    ' assuming your data starts on row 1 of column K and there's no blank cells.  If there are, just pick a value big enough to cover your whole data range.
         UM = cells(Asweep, 11).value
         UN = left$(UM, Len(UM) - 3) & right$(UM, 2)
         cells(Asweep, 11).value = UN
    next ASweep
    Last edited by swoop99; 01-23-2012 at 04:24 PM.

  3. #3
    Valued Forum Contributor
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2003
    Posts
    2,488

    Re: Macro to Delete Spaces between text and numbers in a cell

    hi bigdee008@yahoo.com, please check attachment, run code "test". The code is based on the example rows provided.
    Attached Files Attached Files
    Last edited by watersev; 01-23-2012 at 04:42 PM.

  4. #4
    Registered User
    Join Date
    12-30-2011
    Location
    London, Ont
    MS-Off Ver
    Excel 2007
    Posts
    61

    Re: Macro to Delete Spaces between text and numbers in a cell

    HI SWOOP 99,... Im getting a syntax error with the code,..

    
    Sub Magic()
    
    Dim ASweep integer
    Dim UM, UN As String
    
    For ASweep = 1 To Range("K65536").End(xlUp).Row    ' assuming your data starts on row 1 of column K and there's no blank cells.  If there are, just pick a value big enough to cover your whole data range.
         UM = Cells(ASweep, 11).Value
         UN = Left$(UM, Len(UM) - 3) & Right$(UM, 2)
         Cells(ASweep, 11).Value = UN
    Next ASweep
    
    End Sub
    Last edited by bigdee008@yahoo.com; 01-23-2012 at 06:54 PM.

  5. #5
    Registered User
    Join Date
    12-30-2011
    Location
    London, Ont
    MS-Off Ver
    Excel 2007
    Posts
    61

    Re: Macro to Delete Spaces between text and numbers in a cell

    Hi watersev; there are tooo many Units of measures, not just CM and MM,.. I just want a macro that would merge the digits to the Unit of measure next to it,..

  6. #6
    Forum Contributor
    Join Date
    06-16-2011
    Location
    London
    MS-Off Ver
    Excel XP
    Posts
    189

    Re: Macro to Delete Spaces between text and numbers in a cell

    Quote Originally Posted by bigdee008@yahoo.com View Post
    HI SWOOP 99,... Im getting a syntax error with the code,..
    My bad, that should be

    
    Dim ASweep as integer

  7. #7
    Registered User
    Join Date
    12-30-2011
    Location
    London, Ont
    MS-Off Ver
    Excel 2007
    Posts
    61

    Re: Macro to Delete Spaces between text and numbers in a cell

    Hi watersev; there are tooo many Units of measures, not just CM and MM,.. I just want a macro that would merge the digits to the Unit of measure next to it,..

  8. #8
    Valued Forum Contributor
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2003
    Posts
    2,488

    Re: Macro to Delete Spaces between text and numbers in a cell

    can you provide worksheet with data and expected result?

+ 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.2.0