+ Reply to Thread
Results 1 to 2 of 2

Using an Array to set Column Widths when Importing a Fixed Width Text File

  1. #1
    Forum Contributor
    Join Date
    07-07-2014
    Location
    ericbartha.com
    MS-Off Ver
    2016 Professional
    Posts
    126

    Using an Array to set Column Widths when Importing a Fixed Width Text File

    Hello everyone,

    I having only been using VBA for a few months and am new to arrays. I have a Fixed Width file which I am trying to import and force the width of the columns based on information that comes with the file. ie. start character, end character, and length of characters. I've already created an Array which is pulling in and storing the list of character lengths. Now, while actually opening the text file, I want to use that array to set the widths. Yet, I cannot get it to work as I keep getting an "Invalid procedure call or argument" error.

    My code is broken up into 4 different subs but the first one is what creates the array and the last one is what is using the array.

    Note: I did originally try Workbooks.OpenText instead of the QueryTables.Add function, but from what I can tell you cannot specify column widths with the former. Is this true?

    Any help would really be appreciated!!!

    Please Login or Register  to view this content.

  2. #2
    Forum Contributor
    Join Date
    07-07-2014
    Location
    ericbartha.com
    MS-Off Ver
    2016 Professional
    Posts
    126

    Re: Using an Array to set Column Widths when Importing a Fixed Width Text File

    Since no one replied, I am updating with my solution in case it can help anyone later down the road.

    The issue was with initializing my array. The range that was being used to populate the array was stored vertically, lets say cells C11:C77. I had to wrap this initialization of the array with an Application.Transpose. See below. Upon doing so, everything worked fine. Simple oversight but I was unaware that Excel arrays could be stored in such a manner. I assumed that they were stored horizontally.

    Please Login or Register  to view this content.

+ 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. Importing Fixed Width Text Data Into Excel
    By jgsuf in forum Excel General
    Replies: 3
    Last Post: 08-21-2014, 01:48 PM
  2. [SOLVED] Pulling data from a text file, splitting by fixed column width
    By ferynd in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-15-2013, 08:21 PM
  3. [SOLVED] Changing fixed width (column break) defaults when importing text
    By NaughtonNJ in forum Excel General
    Replies: 1
    Last Post: 05-03-2006, 01:20 PM
  4. Importing file with fixed width, multi-line records
    By danmcgov in forum Excel General
    Replies: 7
    Last Post: 03-20-2006, 04:10 PM
  5. [SOLVED] Importing Fixed Width File Macro
    By Himansu in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-06-2005, 01:05 PM
  6. [SOLVED] Best way to import fixed-width delimited text files into an array?
    By KR in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-03-2005, 11:06 AM
  7. Basic Q: Field/Array info when importing fixed-width text files
    By KR in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-01-2005, 05:06 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