+ Reply to Thread
Results 1 to 8 of 8

Sentence seperation macro EX VB

  1. #1
    Registered User
    Join Date
    01-16-2014
    Location
    uk
    MS-Off Ver
    Excel 2013
    Posts
    99

    Sentence seperation macro EX VB

    Hi

    I am working on a template worksheet and will be pasting external data onto the template sheet daily then reverting back to the fresh blank template worksheet the following day.
    Some of the data i am pasting is in sentence format, pasted to 1 cell, which i need that data seperated along the following columns.
    I have tried using text to columns on data tab but it looks like i need a macro for Visual Basic to format the sheet, I have just started learning VB over the last week so not an expert but if someone can provide a macro so i can format the sheet, i really would appreciate it.

    I have attached a sheet as example: YELLOW IS PASTED WITHOUT FORMAT/ GREY IS HOW I NEED IT TO LOOK WHEN PASTED.

    Thanks for your time.
    Attached Files Attached Files

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Sentence seperation macro EX VB

    Hi,

    Why complicate what is a simple task by resorting to VB.

    Just use the TextToColumns functionality and specify the space character as the delimiter.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Sentence seperation macro EX VB

    Try some thing like this...

    How to install your new code
    1. Copy the Excel VBA code
    2. Select the workbook in which you want to store the Excel VBA code
    3. Press Alt+F11 to open the Visual Basic Editor
    4. Choose Insert > Module
    5. Edit > Paste the macro into the module that appeared
    6. Close the VBEditor
    7. Save your workbook (Excel 2007+ select a macro-enabled file format, like *.xlsm)

    Please Login or Register  to view this content.
    To run the Excel VBA code:
    1. Press Alt-F8 to open the macro list
    2. Select a macro in the list
    3. Click the Run button


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  4. #4
    Registered User
    Join Date
    01-16-2014
    Location
    uk
    MS-Off Ver
    Excel 2013
    Posts
    99

    Re: Sentence seperation macro EX VB

    Sixthsense thanks ill give that a go.

    Richard it is a template sheet which i will be using daily and i dont want to have to go through the texttocolumn routine every time i open up the sheet. unless you know of a way to format the sheet so the column in question always performs the action without having to format evertime i open up the template?

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Sentence seperation macro EX VB

    In that case SixthSense's macro will perform the TextToColumns functionality for you.

    You'll need to put the code in the Workbook open event (or Call it from the open event) if you want it to happen each time the workbook is opened.

  6. #6
    Registered User
    Join Date
    01-16-2014
    Location
    uk
    MS-Off Ver
    Excel 2013
    Posts
    99

    Re: Sentence seperation macro EX VB

    Sixthsense that worked thankyou but what i forgot to mention was that either side of the column formated there is extra pasted data which is not a sentence needing slip for example

    DATA/DATA/SENTENCEDATA/DATA/DATA

    So i need to push the columns after the sentence slip format forward so not to lose pasted data in pre or following columns.

    I edited your macro to C1 as thats where the pasted data will appear, I started in C1 and what happened is your macro worked but overwrote the pasted data in A1&B1

    If you can edit the macro for me that would be great thank you

  7. #7
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Sentence seperation macro EX VB

    Hi,

    The easiest way is to add say 4 columns before running the macro.
    e.g. Assuming the text column to be split is column A

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    01-16-2014
    Location
    uk
    MS-Off Ver
    Excel 2013
    Posts
    99

    Re: Sentence seperation macro EX VB

    Hi Richard

    I have attached a sheet showing exactly how the pasted data will appear, column C is where the macro needs to split the data without overwriting other pasted data either side, The macro works and just needs editing with maybe an insert column string added to the macro.

    Sub ApplyTextToColumnsInCode()

    With Range("C1", Cells(Rows.Count, "C").End(xlUp))
    .TextToColumns Destination:=Range("F1"), DataType:=xlDelimited, _
    ConsecutiveDelimiter:=True, Space:=True
    End With

    End Sub

    Attached Files Attached Files

+ 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. Data seperation
    By sathishkm in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-20-2013, 03:15 PM
  2. Words and number seperation.
    By Andy Stringer in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 11-15-2012, 04:45 AM
  3. Data seperation
    By skalynuik in forum Excel General
    Replies: 1
    Last Post: 03-31-2012, 10:01 AM
  4. Data Seperation
    By graeme86 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-09-2008, 11:30 AM
  5. [SOLVED] Date Seperation
    By MBlake in forum Excel General
    Replies: 2
    Last Post: 04-20-2005, 09:06 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