+ Reply to Thread
Results 1 to 4 of 4

How to delete block of elements from stored VBA array string

  1. #1
    Registered User
    Join Date
    09-27-2010
    Location
    England
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    20

    Question How to delete block of elements from stored VBA array string

    Hi all,

    I'm currently working with a file which is read into an array (single dimension) string e.g. MyArray() As String.
    The format of the file is something like this:
    HTML Code: 
    and so on with hundreds of PACKAGES and typically >40000 lines (array elements).
    NOTE: End of line treatment is CRLF in the original file.

    I would like to know if it is possible to delete a block of elements between and including the "begin members" and "end members" in one go.
    Currently I am testing looping through each PACKAGE, finding the "begin member" line deleting each individual line and resizing , preserving array until "end member" for each function and it is taking ages .
    However, if it were possible to delete element "chunks" at a time and then resize/preserve array for each PACKAGE rather than for each line then maybe code could be faster.

    Rough example of current code (being tested):
    Please Login or Register  to view this content.
    In case you're wondering why I want to delete these sections.
    I am really only interested in each "package name" and corresponding info in the "begin parts" and "end parts" and will do some processing of this remaining info. Reducing MyArray() size by deleting unnecessary elements may help speed up subsequent post processing of the info.

    I basically want to be left with the following before starting to process array with other functions:
    HTML Code: 
    Any help offered or ideas in the most efficient way of deleting the unnecessary blocks of elements would be appreciated.

    nutty

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: How to delete block of elements from stored VBA array string

    Hi

    would it be possible to take a copy of the column of data (I'm assuming that the data is all in one column), and delete the unnecessary items in that column, then put the end result into the array? May be faster than trying to delete from the array. Or perhaps go the other way and build the array with the required data.

    An example file showing your structure may also help.

    rylo

  3. #3
    Registered User
    Join Date
    09-27-2010
    Location
    England
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    20

    Re: How to delete block of elements from stored VBA array string

    Hi rylo,

    Thank you for your reply and suggestions. I think the second option you have given
    Or perhaps go the other way and build the array with the required data.
    is the direction I am leaning towards. I have been searching the web for a block wise element delete but have yet to come across such an example which makes me think it isn't such a good idea otherwise it would have been a common solution . Thanks again for your suggestions.

    It would still be interesting to me to know whether it is possible to delete a block of elements from the array rather than line by line approach...

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How to delete block of elements from stored VBA array string

    There's no inbulit functionality that allows you to delete blocks of an array.

    A workaround could probably be created but it might need to be specific for the situation.

    The way I was thinking was that the array could be joined using a delimiter, then something like InStr could be used to find the 'block' you want to delete.

    Then extract everything before the block, concatenate that to everything after the block and finally split the string to get the array.
    If posting code please use code tags, see here.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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