+ Reply to Thread
Results 1 to 9 of 9

EXCEL Text to Columns macro with a variable numberof Fields

  1. #1
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    EXCEL Text to Columns macro with a variable numberof Fields

    Hi Guys,
    I've go a question again about something that I can't seem to put together.

    The code below works fine for the 41 columns and does exactly what it needs to do
    Please Login or Register  to view this content.

    What I am trying to figure out is how can y use variable list of fields for the FiledInfo

    I have this routine in the macro that checks how many columns are in the first row of the importet text file

    Please Login or Register  to view this content.
    The contents of fInfoArrList will vary in relation to the what the text file contains

    Please Login or Register  to view this content.
    The question is how can this be made to work?

    Hope my explanation makes sense
    Thanks for looking and any ideas or tips are welcome.

    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,507

    Re: EXCEL Text to Columns macro with a variable numberof Fields

    Instead of building a string, why not ReDim an array the size you want and then loop through it making each entry in the array represent a column … much as you have done with the string. That way, you end up with an array. Hopefully you can use that in the text to columns.

    Totally untested but an idea to play with.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,256

    Re: EXCEL Text to Columns macro with a variable numberof Fields

    Yes, you need an array whose elements are themselves arrays.
    Remember what the dormouse said
    Feed your head

  4. #4
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: EXCEL Text to Columns macro with a variable numberof Fields

    Thanks @TMS adn @rorya, the array, yes, that's tru a single array, I was confused by the Array(1,1) all I need then is one dimentional array .
    I'm off to be now and will look and test tomorrow, I was making it more difficult than it really is.
    Thanks again, will update tomorrow (if I get it done) and will also post the code snippet
    Good-night

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,256

    Re: EXCEL Text to Columns macro with a variable numberof Fields

    A 1D array of arrays to be specific.

  6. #6
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: EXCEL Text to Columns macro with a variable numberof Fields


    Hi,

    as FiedInfo parameter is optional and according to the initial post code as all columns are set to general so it is useless, can be removed !

    When this parameter is really necessary - for example to convert dates - you can use an array for the non general columns …

  7. #7
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: EXCEL Text to Columns macro with a variable numberof Fields

    @Marc L: I agree and this is the default setting, once I get that working I have a table that checks the ghearder name where it reads if it's a date or a general or specific text setting, thta's why I'm trying to figure it out
    Tried array one D and 2D but it doesn't work

    My last attempt as 2D array no go either
    Please Login or Register  to view this content.
    Thanks anyway, will find another way

  8. #8
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,256

    Re: EXCEL Text to Columns macro with a variable numberof Fields

    2D is wrong. You need a 1d array and each element of that is also a 1D array

  9. #9
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: EXCEL Text to Columns macro with a variable numberof Fields

    Hi guys, thanks and i got it working, now only the finetuning but thanks

    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. Macro to Export Variable columns from One Excel Work Sheet to another
    By naresh73 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-21-2013, 11:01 AM
  2. Replies: 1
    Last Post: 10-27-2012, 02:54 AM
  3. [SOLVED] How to add counter to monitor numberof edits and copy this data in diff cells??
    By CHETANHADIMANI in forum Excel - New Users/Basics
    Replies: 27
    Last Post: 07-20-2012, 02:25 PM
  4. Scan through row 1 fields for specified text and record the column in a variable
    By wfogel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-28-2010, 04:49 PM
  5. Import text fields into columns from txt file
    By Pshawn in forum Excel General
    Replies: 3
    Last Post: 01-28-2010, 12:30 PM
  6. Import Text file Fields as Columns in Excel
    By vijay2482 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-12-2009, 11:05 AM
  7. [SOLVED] Excel SHOULD NOT AUTO-CHANGE formated text fields to DATE FIELDS!
    By PSSSD in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 08-08-2006, 04:35 PM
  8. [SOLVED] how to compare text fields in 2 different columns in excel
    By ljt1 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-31-2006, 07:25 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