+ Reply to Thread
Results 1 to 3 of 3

Thread: removing spaces in barcode

  1. #1
    Registered User
    Join Date
    01-28-2009
    Location
    Quebec, Canada
    MS-Off Ver
    Excel 2007
    Posts
    6

    Question removing spaces in barcode

    I have a table with approximately 1000+ lines of bar-codes looking like this the info is all in one column which is C

    7 84695 99241 3
    7 84695 99242 0
    784695 99243 7
    7 84695 992444
    7 84695992451
    7 84695 99246 8

    the space is all over not sure why the bar-codes aren't entered all the same way,
    what I need is that all the space must be removed

    I have tried =substitute(c1," ","") which works fine but now I must copy this formula for all of the column C

    Is their a range function or vb code to do this for all the column C

    thanks
    Last edited by Navop; 01-09-2012 at 11:49 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    06-09-2010
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007 and 2010
    Posts
    346

    Re: removing spaces in barcode

    You could do this in several ways, here are three that might work

    1. select column C and run search and replace entering a space in the search box

    2. Add a column to the right of column C, enter your fomula in cell D1, copy it into all the cells in column D adjacent to a value in column C. Select the contents of column D and click copy > paste special > paste values

    3. Run this macro:

    Sub substitute_blanks()
    Dim n
    For n = 1 To ActiveSheet.UsedRange.Rows.Count + 1
        Columns("C").Cells(n).Value = Replace(Columns("C").Cells(n).Value, " ", "")
    Next n
    End Sub

  3. #3
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    Excel 2007
    Posts
    6,206

    Re: removing spaces in barcode

    Or this code for selected cells:
    (select cells and run macro)

    Public Sub Remove_space()
    Dim rngArea As Range
    For Each rngArea In Selection.Areas
        With rngArea
            .Value = Evaluate("IF(ISTEXT(" & .Address & "),SUBSTITUTE(" & .Address & ","" "",""""),REPT(" & .Address & ",1))")
            .NumberFormat = "0"
        End With
    Next rngArea
    End Sub
    "Relax. What is mind? No matter. What is matter? Never mind!"

+ 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