+ Reply to Thread
Results 1 to 11 of 11

Error 1004 in certain line - The code works until line 152

  1. #1
    Registered User
    Join Date
    02-28-2017
    Location
    Chile
    MS-Off Ver
    2010
    Posts
    9

    Unhappy Error 1004 in certain line - The code works until line 152

    Hi everyone,
    As the title said I have the 1004 error with in my code i = 153. This code copy the value of serial number from the Sheet "Control de Triconos" to another sheets called F101, F102, etc between a range of dates in two turns A and B. The code reads the respective sheet name in "Control de Triconos" cols n°2, but when i = 153 the program crashes and got the error number 1004.

    The code is:

    Please Login or Register  to view this content.
    Plz help me!
    Sorry for my bad english and THX to all
    Last edited by REspina; 03-01-2017 at 03:23 PM.

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Error 1004 in certain line - The code works until line 152

    Hola REspina,

    Por favor, lee las reglas del foro, especialmente #3? Gracias.

    Can you provide a copy of your workbook? It seems strange to get an error there at 152 (or 153) because if the error did not happen before then it should not happen at that number...

    Just in case though, I do suggest adding .Value at the end of cell references when it is their value you are looking at:

    Please Login or Register  to view this content.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Error 1004 in certain line - The code works until line 152

    Also, if i j and k are just loop variables that will not have decimals, then it is usually better to Dim as Long instead of Double.

    Thanks for fixing your post to add Code Tags

  4. #4
    Registered User
    Join Date
    02-28-2017
    Location
    Chile
    MS-Off Ver
    2010
    Posts
    9

    Re: Error 1004 in certain line - The code works until line 152

    Quote Originally Posted by Arkadi View Post
    Hola REspina,
    Can you provide a copy of your workbook? It seems strange to get an error there at 152 (or 153) because if the error did not happen before then it should not happen at that number...
    Sorry for badposting !
    I can provide you the code (but idk how), but it has another mini-codes for others fuction. The yellow commandbutton is the problem, I tried everything but it still doesn't work and i'm getting mad with this.

  5. #5
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Error 1004 in certain line - The code works until line 152

    REspina, lo que quiero ver es el "workbook"... porque el problema me parece muy extran~o y logicamente no veo porque. Para poner el workbook en tu post, aprieta "Go Advanced" bajo el mensaje (en la esquina derecha de la pagina). Ahi veras un a opcion para "Manage Attachments", la cual te dejara escoger una "file" para mandar.

    Mi espan~ol no es tan bueno como antes

    Pero trataste lo que sugeri de an~adir ".Value" y cambiar "Double" a "Long"?

  6. #6
    Registered User
    Join Date
    02-28-2017
    Location
    Chile
    MS-Off Ver
    2010
    Posts
    9

    Re: Error 1004 in certain line - The code works until line 152

    Quote Originally Posted by Arkadi View Post
    Pero trataste lo que sugeri de an~adir ".Value" y cambiar "Double" a "Long"?
    I did, but the code still crashing.
    Here is my workbook y deleted some stuff due to the weight of archive.

    The yellow button is the problem.
    Attached Files Attached Files
    Last edited by REspina; 02-28-2017 at 03:22 PM.

  7. #7
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Error 1004 in certain line - The code works until line 152

    I tried.... when i = 152 it takes very long... and j goes very high, but eventually it got to i = 153 and no error.

    I also tried at the start i=153, with no error.

    BUT: The code in the workbook is not exactly the same as what you posted. When I try the code you put here in your first post, the error does come when i = 152, I think because your code uses j for row number. When j reaches 1,048,576 (which is maximum rows in excel), then this line: "Sheets(Equipo).Cells(j + 1, 1)" means row 1,048,577, which does not exist in excel 2010 (and 2013/2016).

    So you need to look at your code, and fix it so j does not go above 1,048,575 (I think that is way too high anyway, probably you need to fix the loops)

  8. #8
    Registered User
    Join Date
    02-28-2017
    Location
    Chile
    MS-Off Ver
    2010
    Posts
    9

    Re: Error 1004 in certain line - The code works until line 152

    Quote Originally Posted by Arkadi View Post
    I tried.... when i = 152 it takes very long... and j goes very high, but eventually it got to i = 153 and no error.

    I also tried at the start i=153, with no error.

    BUT: The code in the workbook is not exactly the same as what you posted. When I try the code you put here in your first post, the error does come when i = 152, I think because your code uses j for row number. When j reaches 1,048,576 (which is maximum rows in excel), then this line: "Sheets(Equipo).Cells(j + 1, 1)" means row 1,048,577, which does not exist in excel 2010 (and 2013/2016).

    So you need to look at your code, and fix it so j does not go above 1,048,575 (I think that is way too high anyway, probably you need to fix the loops)
    I reset the value before the line with the problem. The code doesn't let to j go too high so the problem isn't the value of j; I put a break in the line with the problem and changed my code to start with i = 152 and got the same problem.

    I'm afraid now, this macro is for a management system for sales to entire continent plz help me :/

  9. #9
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Error 1004 in certain line - The code works until line 152

    Well here was my test:

    I put "On Error GoTo Errores" at the start, change i =2 to i=152 so you don't have to wait so long, and I changed "Errores:
    MsgBox (Err.Description)" to :

    Please Login or Register  to view this content.
    This told me that j was the maximum number of rows when the error happened, and j+1 as a row number does not exist. You want to modify your code so that the looping stops when the last row with data has been reached, because "Do Until Sheets(Equipo).Cells(j, 1) & Sheets(Equipo).Cells(j, 2) = F_termino" will never stop if the cell never matches the value of F_termino

  10. #10
    Registered User
    Join Date
    02-28-2017
    Location
    Chile
    MS-Off Ver
    2010
    Posts
    9

    Re: Error 1004 in certain line - The code works until line 152

    Thank you so much Arkadi for identify the problem.
    Exactly j reaches the max value soported for excel, so in the line j+1 the program crashes. I manage a solution adding an extra line in the date data with null values, so the program stops reading in the next to last row avoiding to j to increase it value.

    Arkadi again thx so much, if you visit Chile in the future I'll invite the beers.

  11. #11
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Error 1004 in certain line - The code works until line 152

    Entonces ya no es necesario ponernos en contacto?
    Please mark the thread as solved if the problem is gone?
    I'm glad I was able to help... I was about to examine the code in more detail to find a solution for your problem, but sounds like you have it fixed... I bet it is faster now too?
    I've never been further south than Costa Rica, but I would love to visit Chile, maybe I'll see you there some day. I grew up in Costa Rica/Nicaragua.

+ 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] Run-time error '1004' when executing Exit Sub command line
    By Henk Stander in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 08-29-2014, 02:50 AM
  2. [SOLVED] Run time error 1004 - why is the last line of this code causing this?
    By SweetSorcery in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 07-14-2014, 06:57 AM
  3. [SOLVED] Excel Border Line style works for the first time I run the code, later it shows some error
    By vidyaduttk in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-14-2014, 05:41 AM
  4. 8 Line Code Works On Other Computer, Not Mine
    By Relmiw in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-11-2014, 09:45 PM
  5. [SOLVED] Need help understanding why this line of code works.
    By jbwitty in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 09-26-2013, 01:01 AM
  6. Run time Error 1004 in 5th line of IF..THEN..ELSE
    By go-fish in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-19-2010, 05:17 AM
  7. combining sheets (code works from ron debruin but need 1 line modification)
    By Piyush in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-04-2005, 12:38 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