+ Reply to Thread
Results 1 to 3 of 3

Macro to delete certain contents of a cell

  1. #1
    Registered User
    Join Date
    06-25-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 2003
    Posts
    24

    Macro to delete certain contents of a cell

    Good Day Everyone,

    I've come across an issue where I need to remove some data from a cell, but preserve other parts of it.

    Here is an example the cells I am working with contain a part number, OR a part number AND a UPC.

    So either "1234" as a part number or "1234 | 089761231872" as a part number and UPC combination.

    I have two goals. First is to eliminate all of the cells that contain ONLY part numbers. Those cells have no separator symbol such as |. The other goal is to remove the part number and the separator symbol from the cells that contain BOTH part number and UPC, which would effectively leave me with a column of blank cells, and upc numbers.

    Here is an image of my work book:

    In this image column K is the current data set. You can part numbers by them self (row 65-70 and 75-85) and you can see part numbers and upcs together (row 71 to 74).

    Column L shows the desired outcome. Only UPCs and all else blank if no UPC present.

    http://imgur.com/yUnup

    I have tried fiddling with my limited macro knowledge but have no been successful as of yet. Any assistance would be appreciated.

    Thanks so much,
    Mike.

  2. #2
    Forum Contributor
    Join Date
    03-21-2012
    Location
    Ho Chi Minh city
    MS-Off Ver
    Excel 2003
    Posts
    180

    Re: Hope this help for you

    PHP Code: 
    Option Explicit
    Sub CopyPart
    ()
     
    Dim Rng As RangesRng As Range
     Dim MyAdd 
    As String
     Dim ViTri 
    As Byte
     
    Const UPC As String "|"
     
     
    Set Rng Columns("K:K")
     
    Set sRng Rng.Find(UPC, , xlFormulasxlPart)
     If 
    Not sRng Is Nothing Then
        MyAdd 
    sRng.Address
        
    Do
            
    With sRng
                ViTri 
    InStr(.ValueUPC) + 1
                
    .Offset(, 1).Value Mid(.ValueViTriLen(.Value))
            
    End With
            Set sRng 
    Rng.FindNext(sRng)
        
    Loop While Not sRng Is Nothing And sRng.Address <> MyAdd
     End 
    If
    End Sub 

  3. #3
    Registered User
    Join Date
    06-25-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: Macro to delete certain contents of a cell

    Wow that is impressive. I wasn't even close lol.

    Thanks so much for your time, that made life a lot easier.

+ 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