+ Reply to Thread
Results 1 to 26 of 26

Error 1004 when I use a Range.Find

  1. #1
    Registered User
    Join Date
    01-02-2021
    Location
    Úbeda (Spain)
    MS-Off Ver
    Microsoft Office 365
    Posts
    46

    Error 1004 when I use a Range.Find

    Good afternoon and happy new year.

    I am new here. Let's see if you can help me with a problem I have.

    I have developed a function where I use find to find the cell that corresponds to today's date. However, it gives me an error 1004 that I don't know why it happens. What I have done has been to add an error control to skip it, but I want to know the reason for the error, to know if it can be solved before killing flies with gunfire.

    This is the function:

    Please Login or Register  to view this content.
    I also enclose the book so that you can see the best procedure. You just have to click on the button on the right above and it will give you the error.

    Thank you!
    Attached Files Attached Files

  2. #2
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,236

    Re: Error 1004 when I use a Range.Find

    Not sure what you are trying to do but this will give you an idea...
    Please Login or Register  to view this content.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  3. #3
    Registered User
    Join Date
    01-02-2021
    Location
    Úbeda (Spain)
    MS-Off Ver
    Microsoft Office 365
    Posts
    46

    Re: Error 1004 when I use a Range.Find

    Quote Originally Posted by sintek View Post
    Not sure what you are trying to do but this will give you an idea...
    Please Login or Register  to view this content.
    Hello, thanks for answering.

    I have tried what you propose and it still does not work without errors.

    This sheet is a summary of hours by tasks, and to avoid having to stop each month to add a new month, copying a row, looking for which cells I have to expand the range ... what I do is automate it.

    Also, and this is where I think the problem is, is that I have created custom formulas to calculate the data that I need to have, hence why you see so many functions in the VBA project. You can see it in the purple cells.

    Let's see, the problem is solved as I indicate, adding an error control, capturing the 1004, and doing nothing. But I want to know why it gives this error, in case it could affect something else that I have on the sheet.

  4. #4
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,236

    Re: Error 1004 when I use a Range.Find

    Like I said...No idea what you are trying to do...The code was just an example to show you that it finds the date in row 19...

  5. #5
    Registered User
    Join Date
    01-02-2021
    Location
    Úbeda (Spain)
    MS-Off Ver
    Microsoft Office 365
    Posts
    46

    Re: Error 1004 when I use a Range.Find

    Well then, thank you very much for the time. I have tried to simplify, so that instead of leaving the MsgBox that you have put me six times, it only comes out once, let's see if that's the case, but neither.

    Let's see if someone else comments something different.

  6. #6
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,236

    Re: Error 1004 when I use a Range.Find

    where I use find to find the cell that corresponds to today's date
    Like I said...this was just to show you how to find the date...What do you want to do with this date row once you find it?
    Or even better...Explain your required output in step by step and perhaps we can simplify the entire process...
    Please Login or Register  to view this content.
    what must the value of HorasDedicadasMesActual be...
    Last edited by sintek; 01-02-2021 at 01:27 PM.

  7. #7
    Registered User
    Join Date
    01-02-2021
    Location
    Úbeda (Spain)
    MS-Off Ver
    Microsoft Office 365
    Posts
    46

    Re: Error 1004 when I use a Range.Find

    This function is to find the hours of the current month. That is, we are at January-21 (there is still no data for hours, that is, it is empty or null), when it looks for it it tells me that it is in row 19, and then with a Cells, I take that row and put the column two and so I get the hours. And with those hours what I do is obtain various ratios of my interest.

  8. #8
    Registered User
    Join Date
    01-02-2021
    Location
    Úbeda (Spain)
    MS-Off Ver
    Microsoft Office 365
    Posts
    46

    Re: Error 1004 when I use a Range.Find

    Quote Originally Posted by sintek View Post
    what must the value of HorasDedicadasMesActual be...
    the value in column b corresponding to the date of the current month

    for example, for last month it was 87:05

  9. #9
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,236

    Re: Error 1004 when I use a Range.Find

    the value in column b corresponding to the date of the current month
    This is how I understand your function???
    Same as post 6 code...
    Please Login or Register  to view this content.
    Last edited by sintek; 01-02-2021 at 01:45 PM.

  10. #10
    Registered User
    Join Date
    01-02-2021
    Location
    Úbeda (Spain)
    MS-Off Ver
    Microsoft Office 365
    Posts
    46

    Re: Error 1004 when I use a Range.Find

    yes, that's right, you got it

  11. #11
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,830

    Re: Error 1004 when I use a Range.Find

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however it has been brought to our attention that the same query has been posted on one or more other forums and you have not provided the required cross-post link(s) here.

    Please see Forum Rule #3 about cross-posting and adjust accordingly. Read this to understand why we (and other sites like us) consider this to be important.

    (Note: this requirement is not optional. As you are new, I'll provide the link for you this time: https://www.mrexcel.com/board/thread...-find.1157355/.)
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  12. #12
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,236

    Re: Error 1004 when I use a Range.Find

    So what is wrong with post 6 code...Does all you require...
    How are the other columns in row 19 populated...

  13. #13
    Registered User
    Join Date
    01-02-2021
    Location
    Úbeda (Spain)
    MS-Off Ver
    Microsoft Office 365
    Posts
    46

    Re: Error 1004 when I use a Range.Find

    Ok, I'm sorry. I won't do in the future

  14. #14
    Registered User
    Join Date
    01-02-2021
    Location
    Úbeda (Spain)
    MS-Off Ver
    Microsoft Office 365
    Posts
    46

    Re: Error 1004 when I use a Range.Find

    Quote Originally Posted by sintek View Post
    So what is wrong with post 6 code...Does all you require...
    How are the other columns in row 19 populated...
    If it is not bad, it is perfect, the issue is that when copying row 12 below the last filled row, with the button you have on the top right, I get error 1004. The function is AñadirNuevoMesFocusToDo

  15. #15
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,236

    Re: Error 1004 when I use a Range.Find

    If I were you...I would get rid of all that functions and tell us exactly what it is you are trying to achieve...
    I suspect that one sub will provide everything you need...if only we knew what you are trying to achieve...

    Looks like you are just trying to increment date lines and populate the columns B to S with values and formulas...

  16. #16
    Registered User
    Join Date
    01-02-2021
    Location
    Úbeda (Spain)
    MS-Off Ver
    Microsoft Office 365
    Posts
    46

    Re: Error 1004 when I use a Range.Find

    Quote Originally Posted by sintek View Post
    If I were you...I would get rid of all that functions and tell us exactly what it is you are trying to achieve...
    I suspect that one sub will provide everything you need...if only we knew what you are trying to achieve...

    Looks like you are just trying to increment date lines and populate the columns B to S with values and formulas...
    I have translated the sheet for you, except for the dates, which I could not, and I have added comments with what each thing means. Let's see if it is clear to you what I want to achieve.
    Attached Files Attached Files

  17. #17
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,236

    Re: Error 1004 when I use a Range.Find

    You have not yet answered my question...
    Looks like you are just trying to increment date lines and populate the columns B to S with values and formulas...
    So the button that you press...I am trying to ascertain if one can provide a more simplistic solution with one sub instead of all these functions...
    If this is the case as per my question quoted above...then we will need to only know what value|formula needs to go into Columns B to S
    Seems all the information is available on this sheet to allow for this...

    If you are open to this all you need to provide is a result for Row 19 January-21 with the answers in Columns B to S and explain how these answers were calculated...
    Seems this button will be pressed once only every month...Not so?

    Also...I notice you have not implemented the code I provided so this file is still giving the error...|Have you even tried implementing it...

  18. #18
    Registered User
    Join Date
    01-02-2021
    Location
    Úbeda (Spain)
    MS-Off Ver
    Microsoft Office 365
    Posts
    46

    Re: Error 1004 when I use a Range.Find

    Yes I implemented it, what happens to you is that as I have been testing, I will have sent you the Excel with the comments in the original, not the one in which I have tested what you were telling me.

    Sure enough, I only push that button once a month. Then all the information is on this sheet.

    Other things I have tried: if I disable all volatile functionals, it does not give error 1004 when pressing the button.

    Thank you

  19. #19
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,236

    Re: Error 1004 when I use a Range.Find

    I have provided advice...I am only able to offer a simplistic solution by not using all your functions if you are able to ...
    If you are open to this all you need to provide is a result for Row 19 January-21 with the answers in Columns B to S and explain how these answers were calculated...
    If not...I apologize for wasting your time...Perhaps someone else is willing to hop on board and offer a fix to your function problem as my code has not solved this...

  20. #20
    Registered User
    Join Date
    01-02-2021
    Location
    Úbeda (Spain)
    MS-Off Ver
    Microsoft Office 365
    Posts
    46
    Quote Originally Posted by sintek View Post
    I have provided advice...I am only able to offer a simplistic solution by not using all your functions if you are able to ...


    If not...I apologize for wasting your time...Perhaps someone else is willing to hop on board and offer a fix to your function problem as my code has not solved this...

    How are you going to waste my time, at all. I greatly appreciate your interest. Thanks a lot.

  21. #21
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: Error 1004 when I use a Range.Find

    Once I commented out the error trap, the code went smoothly with no issues.

    I believe this code will get the same results as your code.
    It copies the 2nd last row and pastes it into the 1st empty row then clears the cells without formulas.

    Click the button on attached wb.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  22. #22
    Registered User
    Join Date
    01-02-2021
    Location
    Úbeda (Spain)
    MS-Off Ver
    Microsoft Office 365
    Posts
    46

    Re: Error 1004 when I use a Range.Find

    Goodnight. I put what I have done to solve it.

    Basically, it has been removing Application.Volatile from all functions. That has removed the 1004 error from automating adding a new month using a button. Now, I had to fix the update of the functions. Apparently UDFs update when their arguments change, so I've made sure their arguments actually change. To do this, I had to change a single formula in which I had a UDF without arguments and reference it to others that did change when updating the sheet.

    Finally, and this is not the subject of this question, I have added a custom format: [h]: mm; [Red] - [h]: mm; [Black] [h]: mm.

    Thank you very much for your help!

    PS: I'm so sorry I did cross-posting. It will not happen again.

  23. #23
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,236

    Re: Error 1004 when I use a Range.Find

    Still believe that all that could be simplified with just one tiny macro...But as you are not open to this or had no response to this...Good luck...Happy coding...

  24. #24
    Registered User
    Join Date
    01-02-2021
    Location
    Úbeda (Spain)
    MS-Off Ver
    Microsoft Office 365
    Posts
    46

    Re: Error 1004 when I use a Range.Find

    Thank you for your help.

  25. #25
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: Error 1004 when I use a Range.Find

    I also believe setting calc to manual first would have stopped the udf errors.

  26. #26
    Registered User
    Join Date
    01-02-2021
    Location
    Úbeda (Spain)
    MS-Off Ver
    Microsoft Office 365
    Posts
    46

    Re: Error 1004 when I use a Range.Find

    That would be another solution. Thanks

+ 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. VBA error: runtime error 1004 : Method range of object - 'Global' failed.
    By Afjio12 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-28-2019, 04:37 AM
  2. [SOLVED] Macro Error on Filtering – “Run-time error ‘1004’ Autofilter method of range class failed
    By kschmit1 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-25-2019, 11:49 AM
  3. Runtime error '1004': Paste special method of range class error.
    By Daryl Zer0 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 11-05-2014, 01:44 AM
  4. Replies: 4
    Last Post: 11-15-2013, 05:03 PM
  5. VBA Code...error = run time error 1004 autofilter method of range class failed
    By Dariusd7 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 11-15-2013, 04:49 PM
  6. [SOLVED] VBA Error: Runtime Error 1004: AutoFilter method of Range class failed
    By jl22stac in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-03-2013, 07:27 PM
  7. [SOLVED] Range error in code, runs alone but not inside my full program, giving runtime error 1004
    By charizzardd in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-23-2012, 03:34 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