+ Reply to Thread
Results 1 to 13 of 13

Macro to convert txt to xlsx is giving #N/A error on rows after certain point

  1. #1
    Registered User
    Join Date
    04-22-2021
    Location
    Chicago, Illinois
    MS-Off Ver
    MS Office 2016
    Posts
    12

    Exclamation Macro to convert txt to xlsx is giving #N/A error on rows after certain point

    I have this macro that I am using to take all of the txt files in one folder and save them as xlsx in another folder. However, one of my txt file has around 110,000 rows and this macro is giving #N/A on all of the rows after 55,000. I can't figure out why it is doing that.

    Please Login or Register  to view this content.
    Last edited by excelalejo; 04-22-2021 at 02:01 PM.

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

    Exclamation Re: Macro to convert txt to xlsx is deleting rows inadvertently


    Hi,

    as this 'code' does not delete any row … As per forum rules you must edit your post and use the code tags !

    So it seems there is a bad EOF character in the source text …

  3. #3
    Registered User
    Join Date
    04-22-2021
    Location
    Chicago, Illinois
    MS-Off Ver
    MS Office 2016
    Posts
    12

    Re: Macro to convert txt to xlsx is deleting rows inadvertently

    Thanks. You are right. "Delete" is the wrong word. After a certain row, it is giving me #N/A for all the rows after. I stepped through the macro and the error seems to happen here at this point.

    With ActiveSheet.Range("A1").Resize(LineIndex, 1)
    .Value = WorksheetFunction.Transpose(strLine)
    .TextToColumns Other:=True, OtherChar:="|"

    Edit: Let me try reviewing the EOF. I think I understand now what you are saying. This macro ought to be simple but it is confusing me none the less.

  4. #4
    Registered User
    Join Date
    04-22-2021
    Location
    Chicago, Illinois
    MS-Off Ver
    MS Office 2016
    Posts
    12

    Re: Macro to convert txt to xlsx is giving #N/A error on rows after certain point

    Attachment 729486

    This is what happens, for visual reference.

  5. #5
    Registered User
    Join Date
    04-22-2021
    Location
    Chicago, Illinois
    MS-Off Ver
    MS Office 2016
    Posts
    12

    Re: Macro to convert txt to xlsx is giving #N/A error on rows after certain point

    When I delimit the file myself without the macro, there doesn't seem to be anything special at row 54102 that would trigger that #N/A error. Pictured attached.Attachment 729490

    *Also added tags to VBA code.

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

    Arrow Re: Macro to convert txt to xlsx is giving #N/A error on rows after certain point


    Taking a better glance to your code, you must first check the value of the variable LineIndex just after the Close codeline
    in order to be sure at least the entire text file is well read … If positive, you are certainly right for where the glitch may occur.

    Transpose must be avoided - as maybe still limited to 65K rows - just declaring the array variable as 2 dimensions like Dim strLine(1 to Rows.Count, 0)

    and to allocate a line use Line Input #1, strLine(LineIndex, 0) so ReDim Preserve is no more needed …

    For further help if necessary, an attachment - follow the top page yellow banner - of the source text file will help to investigate your issue
    with an explanation of the expected worksheet layout.

  7. #7
    Registered User
    Join Date
    04-22-2021
    Location
    Chicago, Illinois
    MS-Off Ver
    MS Office 2016
    Posts
    12

    Re: Macro to convert txt to xlsx is giving #N/A error on rows after certain point

    Here is a sample of the file. Just first few rows of data.

    Would it be possible to modify the code using something else besides EOF to ensure entire file is well read to the end regardless of number of lines in original txt file?
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    04-22-2021
    Location
    Chicago, Illinois
    MS-Off Ver
    MS Office 2016
    Posts
    12

    Re: Macro to convert txt to xlsx is giving #N/A error on rows after certain point

    Okay. I just reviewed the transpose as you mentioned and I now see the limit is 65K rows. So seems my entire code needs to be redesigned I guess. The only part that works well is the converting of the file from txt to xlsx and saving the txt files in new folder once converted to xlsx

    When I use the macro recorder, I get this below. Is there someway to remove the EOF and transpose logic in my original code and replace with this and keep everything else as is that is working well? (modifying to accommodate looping through all files in folder) Or do you suggest I take a different approach?

    Please Login or Register  to view this content.

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

    Arrow As solution belongs to good readers …


    Quote Originally Posted by excelalejo View Post
    So seems my entire code needs to be redesigned I guess.
    Not entirely just reading post #6 …

  10. #10
    Registered User
    Join Date
    04-22-2021
    Location
    Chicago, Illinois
    MS-Off Ver
    MS Office 2016
    Posts
    12

    Re: As solution belongs to good readers …

    I see your post #6 however I am unsure how to make that modification in the code. I've tried testing different values in LineIndex but can't correct the error for some reason. Would you be able to help me make the modification?

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

    Arrow Re: Macro to convert txt to xlsx is giving #N/A error on rows after certain point


    As written in post #6 !
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    04-22-2021
    Location
    Chicago, Illinois
    MS-Off Ver
    MS Office 2016
    Posts
    12

    Re: Macro to convert txt to xlsx is giving #N/A error on rows after certain point

    Thank you for your help and your time! I got it to work! Although I did have to make one minor change.

    For this line: "Dim strLine(1 to Rows.Count, 0)" I changed "Dim" to "ReDim". Because, since this line is affecting array size, I was getting "constant expression required error" when using Dim!

    Please Login or Register  to view this content.

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

    Arrow Re: Macro to convert txt to xlsx is giving #N/A error on rows after certain point


    Yes my bad for the Dim codeline 'cause I couldn't test ! The strLine variable can be String rather than Variant …
    EOF is not an issue with 99.999% of text files.

    Thanks for the rep' !

+ 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. [SOLVED] Macro to save .xlsm file as .xlsx rand remove macros and deleting certain tabs
    By robertguy in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-10-2017, 09:55 AM
  2. Help with code to convert xls to xlsx and continue with xlsx file
    By 3345james in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-02-2016, 11:47 AM
  3. Need to convert .ods files into .xlsx using excel macro
    By ranjita_bls in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-24-2015, 06:15 AM
  4. [SOLVED] Macro to convert Xls file format to Xlsx
    By meus in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 05-06-2015, 04:42 AM
  5. Macro to Convert .csv info to .xlsx and save it in another folder under previous name
    By YogurtFace in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-10-2014, 07:14 PM
  6. reg:macro to convert xls to xlsx
    By shankar_eee07 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-14-2012, 09:21 AM

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