+ Reply to Thread
Results 1 to 8 of 8

Macro error with .CSV - too many rows

  1. #1
    Forum Contributor
    Join Date
    07-24-2008
    Location
    Athome
    MS-Off Ver
    Excel 2013
    Posts
    127

    Macro error with .CSV - too many rows

    Hi guys

    I cannot seem to find a solution to my problem by using the search function.

    I have written a Macro in xl2007 in a .xls workbook which copies a sheet from a .csv file and then runs further actions on that sheet. I cannot use .xlsx as there are other users who will use this workbook but don't have excel 2007.

    When I first created the Macro workbook all the procedures worked fine, because althogh the Macro workbook was .xls, it hadn't been closed and re-opened. So it still had 1-million rows.

    When I closed the .xls and re-opened, it now refuses to run the Macro as the error msg states that the .csv file has more rows.

    I have only started with VB about 3-4 weeks ago. Am using xl2007. Not a computer programmer, am an accountant but am pretty good at using excel functions (sumproduct, match, index, sumifs, etc.)

    How do I copy the the .csv sheet (1-mil rows) into my .xls worksheet? (65k rows)

    Here is the code I'm using.

    Please Login or Register  to view this content.
    Last edited by rasonline; 03-10-2011 at 03:38 PM.

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Macro error with .CSV - too many rows

    Hi rasonline,

    Does http://office.microsoft.com/en-us/ex...010077823.aspx help?

    Could it really be the number of rows is too big for 2003 excel?
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Contributor
    Join Date
    07-24-2008
    Location
    Athome
    MS-Off Ver
    Excel 2013
    Posts
    127

    Re: Macro error with .CSV - too many rows

    hi.

    the .csv file is only 400 rows long.
    in the meantime i'm experimenting with the following code

    it's a lot of trial and error as I'm just going along with what I can pick up from internet searches and various forum threads :P Hope I don't sound to amateurish here, but I'm persistent so I'm sure I'll get there eventually.



    Please Login or Register  to view this content.
    I'm copying and pasting all the info from .csv into the .xls file.

  4. #4
    Forum Contributor
    Join Date
    07-24-2008
    Location
    Athome
    MS-Off Ver
    Excel 2013
    Posts
    127

    Re: Macro error with .CSV - too many rows

    Quote Originally Posted by MarvinP View Post
    Hi rasonline,

    Does http://office.microsoft.com/en-us/ex...010077823.aspx help?

    Could it really be the number of rows is too big for 2003 excel?
    The .csv always seems to open with 1-million rows in excel 2007.

  5. #5
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Macro error with .CSV - too many rows

    Have you tried opening the csv file using word or notepad? I wonder if there are really a million rows, most of blank data. Maybe all you need is an End Of File mark at the end of the data.

  6. #6
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Macro error with .CSV - too many rows

    Quote Originally Posted by rasonline View Post
    The .csv always seems to open with 1-million rows in excel 2007.
    When you open a csv file in 2007 it will import it into a 2007 workbook with 1 million rows. As soon as you save it as a .xls file you will revert to working in compatibility mode with 65536 rows. To retain the higher row count you will have to save it as a .xlsx or .xlsm file.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  7. #7
    Valued Forum Contributor
    Join Date
    09-21-2003
    Location
    British Columbia , Canada
    MS-Off Ver
    03,07,10,13
    Posts
    727

    Re: Macro error with .CSV - too many rows

    Please Login or Register  to view this content.
    Workbooks.Open Filename:=FilesToOpen
    In this line you are opening the csv file in excel 2007 ... in other words saving it to a sheet that has 1million lines


    Sheets().Copy After:=ThisWorkbook.Sheets("Instr")
    In this line of code you're attempting to move/copy the entire sheet (i.e. 1 million rows) to a excel 2003 wookbook that cannot contain that many rows.

    SOLUTION:
    Do not attempt to move the entire sheet , instead select the range of data and then only copy/paste the selected range of cells. ... If you could indicate what column , on the source, can be used to determine how many rows have data PLUS how many columns AND the name of the Target sheet , then someone here could help you with the few lines of code it would take to solve the problem. ( see example below)

    Please Login or Register  to view this content.
    Last edited by nimrod; 03-10-2011 at 12:40 PM.

  8. #8
    Forum Contributor
    Join Date
    07-24-2008
    Location
    Athome
    MS-Off Ver
    Excel 2013
    Posts
    127

    Re: Macro error with .CSV - too many rows

    @Nimrod: thanks, solves the problem. I think at post #3 i started heading off on the right track. Your solution allows me to select on the text that I need to.

    @MarvinP: the .csv file is supplied from external source. As Nimrod mentiond, it seems like Excel2007 opens the .csv by default with 1-million lines. So I'm now doing a copy paste into the target workbook.

    Thanks again guys.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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