+ Reply to Thread
Results 1 to 17 of 17

Extract each 10 characters in a cell, and save into an array

  1. #1
    Registered User
    Join Date
    04-09-2013
    Location
    Singapore
    MS-Off Ver
    Microsoft Office Pro Plus or Excel 2007
    Posts
    76

    Extract each 10 characters in a cell, and save into an array

    Hi,

    I have many cells with contents like the below:
    XX Jun2003 XX Mar2007 XX Jan2012

    I want to extract XX Jun2003, XX Mar2007, XX Jan2012 and save each of them into an array.

    The number of such XX mmmyyyy differ for each cell.

    Thank you

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,398

    Re: Extract each 10 characters in a cell, and save into an array

    Do you mean that you want to extract them to separate cells?
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Extract each 10 characters in a cell, and save into an array

    XX Jun2003 XX Mar2007 XX Jan2012

    XX fixed? or can be any character?

    How do you want it?

  4. #4
    Registered User
    Join Date
    04-09-2013
    Location
    Singapore
    MS-Off Ver
    Microsoft Office Pro Plus or Excel 2007
    Posts
    76

    Re: Extract each 10 characters in a cell, and save into an array

    Hi

    1) XX can be any letter in the alphabet
    2) I don't want to extract them into separate cells. I need to test the date for each and remove those that are not within a date range

    Thank you

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Extract each 10 characters in a cell, and save into an array

    Quote Originally Posted by Apple1 View Post
    2) .... I need to test the date for each and remove those that are not within a date range
    What date range?

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Extract each 10 characters in a cell, and save into an array

    Assuming data in col.A
    Don't understand about "date range" and how you use it, so this will just create array of 10 characters in each element.
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    04-09-2013
    Location
    Singapore
    MS-Off Ver
    Microsoft Office Pro Plus or Excel 2007
    Posts
    76

    Re: Extract each 10 characters in a cell, and save into an array

    Hi

    Thank you for yr reply. But can u explain your code? Eg what is "a"?

    Can you just provide a code to extract all the "XX mmmyyyy" in cell A1, and save each of the XX mmmyyyy in an array?

    Thank you
    Last edited by AliGW; 07-05-2020 at 03:03 AM. Reason: Please don't quote unnecessarily!

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Extract each 10 characters in a cell, and save into an array

    1)
    Please don't quote whole posts -- it's just clutter.*If you are responding to a post out of sequence, limit quoted content to a few relevant lines that makes clear to whom and what you are responding

    2) You said
    I want to extract XX Jun2003, XX Mar2007, XX Jan2012 and save each of them into an array.
    Do you really understand what is an "Array" ?

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,398

    Re: Extract each 10 characters in a cell, and save into an array

    Can you just provide a code to extract all the "XX mmmyyyy" in cell A1, and save each of the XX mmmyyyy in an array?
    I think you need to provide a sample workbook with the data as it is now and what you are hoping to achieve mocked up manually. See the instructions at the top of the page.

  10. #10
    Registered User
    Join Date
    04-09-2013
    Location
    Singapore
    MS-Off Ver
    Microsoft Office Pro Plus or Excel 2007
    Posts
    76

    Re: Extract each 10 characters in a cell, and save into an array

    Hi

    An array is a matrix of dimension x*y. I want to save
    MyArray(0) = XX Jun2003
    MyArray(1) = XX Mar2007
    MyArray(2) = XX Jan2012

    Thank you

  11. #11
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,408

    Re: Extract each 10 characters in a cell, and save into an array

    Does this macro do what you want? The last line creates a one-dimensional, zero-based array wherein each array element contains values that contain two letters, a space, the three-letter month name and a four-digit year.
    Please Login or Register  to view this content.
    Note: Data is assumed to be in Column A starting on Row 1.
    Last edited by Rick Rothstein; 07-05-2020 at 03:44 AM.

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Extract each 10 characters in a cell, and save into an array

    That what I did already.
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    04-09-2013
    Location
    Singapore
    MS-Off Ver
    Microsoft Office Pro Plus or Excel 2007
    Posts
    76

    Re: Extract each 10 characters in a cell, and save into an array

    Hi

    Yes this is what I want. Can you explain your code?

    What does this do?
    Please Login or Register  to view this content.
    Thank you

  14. #14
    Registered User
    Join Date
    04-09-2013
    Location
    Singapore
    MS-Off Ver
    Microsoft Office Pro Plus or Excel 2007
    Posts
    76

    Re: Extract each 10 characters in a cell, and save into an array

    Hi

    Can you explain what is a = .Value?

    Why do we need to place the $ in LEFT and TRIM?

    Thank you

  15. #15
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Extract each 10 characters in a cell, and save into an array

    OK, I think I misread your question.
    Please Login or Register  to view this content.

  16. #16
    Forum Guru
    Join Date
    04-23-2012
    Location
    New Jersey, USA
    MS-Off Ver
    Excel 365
    Posts
    2,408

    Re: Extract each 10 characters in a cell, and save into an array

    Quote Originally Posted by Apple1 View Post
    What does this do?
    Please Login or Register  to view this content.
    When assigned to a Variant variable, Application.Transpose takes a vertical range of cells and places them into a one-dimensional array. The Join function then makes a single text string out of the elements of the array using a single space character to delimit them. The next step is to loop the text string every 11 characters starting at position 11. The Mid(S,X)="|" use the Mid in its statement form which allows you to replace characters in a text string at specified positions (in this case, the space character between the values you want). Once those "|" characters have been inserted, the text string is Split at the "|" characters to produce the array you wanted.

    Note: In the future when more than one person has responded to you, you should mention the name of the person you are responding to instead of just saying "Hi" so we know for sure who should respond to your follow up question.

  17. #17
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Extract each 10 characters in a cell, and save into an array

    Quote Originally Posted by Apple1 View Post
    Can you explain what is a = .Value?
    Do a step debug for yourself.
    While you are in VBE;
    1) [View]- [Local Window]
    2) click on somehwere on the code and hit F8.
    3) As you hit F8, the code will execute one line and you will see all the variables in Local Window.
    4) You can expand the varialbe with + sign, so you can see.
    Quote Originally Posted by Apple1 View Post
    Why do we need to place the $ in LEFT and TRIM?
    Open [Object Browser] and enter Left in search box and you will see in the box below.

+ 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. Extract some characters from the cell value
    By Barieq in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-11-2018, 09:04 AM
  2. [SOLVED] Extract all the special characters from each cell
    By SunOffice in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-08-2018, 04:24 PM
  3. How to extract alphanumeric characters from a cell?
    By TECHO in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 12-08-2016, 01:41 AM
  4. Extract only uppercase characters in a cell
    By shmekerie in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-22-2012, 09:39 AM
  5. Extract the first 7 characters of a cell
    By nander in forum Excel General
    Replies: 3
    Last Post: 09-25-2009, 11:13 AM
  6. Extract Text characters only from a cell
    By judasdac in forum Excel General
    Replies: 2
    Last Post: 05-06-2009, 12:22 PM
  7. Extract characters from a cell
    By JBasch in forum Excel General
    Replies: 2
    Last Post: 03-09-2006, 10:30 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