+ Reply to Thread
Results 1 to 3 of 3

Question: Copy and paste split string

Hybrid View

  1. #1
    Registered User
    Join Date
    03-04-2015
    Location
    Minnesota, USA
    MS-Off Ver
    2007
    Posts
    2

    Question Question: Copy and paste split string

    I've been working for a while with tracking numbers that come in through an excel spreadsheet.

    The tracking numbers are in single cells and are in the format, xxxyyy#######zzzz (All numbers)

    For various reasons, I need to leave the original number unchanged. However, I also need to have it split on a seperate worksheet.

    Where:
    the xxx goes in B2
    the yyy goes in C2
    the ####### goes in A23
    the zzzz goes in B23

    I did not design it. I don't know why they designed it this way. I cannot change the design. I wish I could.

    So I'm stuck
    1) manually typing in the numbers into the four locations.
    2) Copying the tracking numbers to a new tab, using text to columns, fixed width to split the string. Than copying and pasting all four to the correct locations.

    Both are a huge time waste.

    What I would like to be able to do is, copy the whole tracking number, than run a macro that takes the string from the clipboard, and auto splits the string into the four sections and pastes the results into the correct cells for me.

    Anyone know how or even if this can be done?

  2. #2
    Forum Expert
    Join Date
    08-28-2014
    Location
    Texas, USA
    MS-Off Ver
    2016
    Posts
    1,796

    Re: Question: Copy and paste split string

    IMPORTANT:
    You need to add the Microsoft Forms 2.0 library to be able to get data off the clipboard in VBA. Instructions on how to do that are here, including what to do in Forms 2.0 isn't listed in the references. Once you add that, you should be fine.

    Sub ninjabear()
    On Error GoTo ErrExplain
    
    Set DataObj = New MSForms.DataObject
       
    DataObj.GetFromClipboard
    
    Tracking = DataObj.GetText(1)
    
    Range("B2").Value = Left(Tracking, 3)
    Range("C2").Value = Mid(Tracking, 4, 3)
    Range("A23").Value = Mid(Tracking, 7, 7)
    Range("B23").Value = Right(Tracking, 3)
    
    
    ErrExplain:
    If Err <> 0 Then MsgBox ("clipboard is empty or does not contain text")
    End Sub

  3. #3
    Registered User
    Join Date
    03-04-2015
    Location
    Minnesota, USA
    MS-Off Ver
    2007
    Posts
    2

    Re: Question: Copy and paste split string

    I wasn't able to get the clipboard to string part to work. (System admin restrictions) So I created a dialogue box to paste the value into and the rest of your code works when I click "Ok". It's not perfect, but it works a lot better now. Thank you,

+ 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] Split String in 3 Blocks of #s, Extract each Block to copy on specific Cell
    By david gonzalez in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-19-2013, 12:14 AM
  2. Split string and copy
    By karinos57 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-01-2010, 03:07 AM
  3. How to split string and copy
    By karinos57 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 04-30-2010, 06:10 PM
  4. Replies: 2
    Last Post: 08-26-2008, 04:03 AM
  5. copy and paste split
    By stevesunfold in forum Excel General
    Replies: 3
    Last Post: 07-20-2008, 02:29 PM

Tags for this Thread

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