+ Reply to Thread
Results 1 to 18 of 18

error 1004 replace method of range class failed

  1. #1
    Registered User
    Join Date
    06-01-2014
    Posts
    8

    error 1004 replace method of range class failed

    Hi all,
    First time poster here, very much a VBA novice- hoping you can help me out!
    I have a sheet of 64227 lines. I've used a substitute formula to get down to a list of categories in column J.
    Because of the substitute formula, each cell contains duplicate values: eg category one, category 1, category 1, category 2.
    I need these cells to just display "category one, category two".
    I've been manually finding and replacing but the scale of the sheet is making this unmanageable.

    So I've created a find and replace macro using this formula:

    Please Login or Register  to view this content.
    But when I click "Run Macro" it converts some values, but not others.
    Debugger points to this line : myRange.Replace What:=cel.Value, Replacement:=cel.Offset(0, 1).Value, LookAt:=xlWhole

    But I can't work out what's causing the problem there.
    I've googled for hours, can anyone shed light on this for me?
    Thanks!
    Last edited by alansidman; 06-01-2014 at 05:08 PM. Reason: code tags

  2. #2
    Valued Forum Contributor
    Join Date
    08-06-2013
    Location
    Detroit, Michigan
    MS-Off Ver
    Excel 2013
    Posts
    671

    Re: error 1004 replace method of range class failed

    So, I don't know enough VBA to tell you why you're getting the error, but if you post a sample workbook, I'd be willing to try a solution.
    1. Include a sample workbook with an example of the result you want
    2. Use [CODE] and [FORMULA] wrappers for your VBA code or excel formulas
    3. If your question has been answered, mark the thread as SOLVED and click on the "Add Rep" star to thank whoever helped you.

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,754

    Re: error 1004 replace method of range class failed

    Code Tags Added
    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between
    Please Login or Register  to view this content.
    tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html



    (Because you are new to the forum, I have added them for you today. Please take a few minutes to read all Forum Rules and comply in the future.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,754

    Re: error 1004 replace method of range class failed

    When you run your macro and it errors out and you look at the highlighted code, what cell has the code stopped at. There is probably some incompatibility with the cell that halts the code. Posting your sheet as K64 would help. Like a doctor trying to diagnose a patient. If he doesn't see the patient, it is difficult to determine what is wrong.

  5. #5
    Registered User
    Join Date
    06-01-2014
    Posts
    8

    Re: error 1004 replace method of range class failed

    anon.xlsx

    Apologies Alan- hope I've included this sample file right!
    If anyone has time to take a look that would be great, it's driving me slowly insane

  6. #6
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,754

    Re: error 1004 replace method of range class failed

    I've looked at your file, but don't understand what you are trying to accomplish. Instead of telling us what you have done, please tell us what your objective is because that is not at all clear from the information shown. The code refers to column J, but there is no data in column J, so I'm guessing you changed things up as well.

  7. #7
    Registered User
    Join Date
    06-01-2014
    Posts
    8

    Re: error 1004 replace method of range class failed

    Apologies, the code should now read:

    Please Login or Register  to view this content.
    What I'm trying to achieve is to replace any value in column a of sheet "client" with the corresponding value from column two in sheet "Sheet1".
    Kind of like an extensive vlookup, if that makes sense?

  8. #8
    Valued Forum Contributor
    Join Date
    08-06-2013
    Location
    Detroit, Michigan
    MS-Off Ver
    Excel 2013
    Posts
    671

    Re: error 1004 replace method of range class failed

    How do you know which ones is the corresponding value?

  9. #9
    Registered User
    Join Date
    06-01-2014
    Posts
    8

    Re: error 1004 replace method of range class failed

    Well, any value in column a of sheet "client" should be replaced with the corresponding value from column b of "sheet 1".
    So, for example, if cell a1 of sheet "client" says "123" and that corresponds to cell a1 of sheet "sheet 1", I'd want to replace that with the value in b1 of sheet "sheet1"- value "1234" for example.
    Does that make sense?

  10. #10
    Valued Forum Contributor
    Join Date
    08-06-2013
    Location
    Detroit, Michigan
    MS-Off Ver
    Excel 2013
    Posts
    671

    Re: error 1004 replace method of range class failed

    Yes, except that none of the values match.

  11. #11
    Registered User
    Join Date
    06-01-2014
    Posts
    8

    Re: error 1004 replace method of range class failed

    hm, uploading here again just incase I messed up versions.



    I have:

    include Exclude pages with High Risk for Suspicious Activity.(XXX), include Exclude pages which XXX has rated as HIGH or MODERATE RISK for Adult Content.(XXX), include Exclude pages which XXX has rated as HIGH or MODERATE RISK for Alcohol Content.(XXX), include Exclude pages which XXX has rated as HIGH or MODERATE RISK for Drug Content.(XXX), include Exclude pages which XXX has rated as HIGH or MODERATE RISK for Hate Speech Content.(XXX), include Exclude pages which XXX has rated as HIGH or MODERATE RISK for Illegal Download Content.(XXX), include Exclude pages which XXX has rated as HIGH or MODERATE RISK for Offensive Language Content.(XXX), include Exclude pages which XXX has rated as HIGH RISK for Adult Content.(XXX), include Exclude pages which XXX has rated as HIGH RISK for Alcohol Content.(XXX), include Exclude pages which XXX has rated as HIGH RISK for Drug Content.(In

    in cell a2 of "client" and of cell a2 of "sheet1".
    Attached Files Attached Files

  12. #12
    Valued Forum Contributor
    Join Date
    08-06-2013
    Location
    Detroit, Michigan
    MS-Off Ver
    Excel 2013
    Posts
    671

    Re: error 1004 replace method of range class failed

    Put this in B2, enter it with ctrl-shift-enter, and drag it down. There are multiple matches. This grabs the last match. Normally, MATCH() is the perfect function for this, but I think the strings are too long for it.
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    06-01-2014
    Posts
    8

    Re: error 1004 replace method of range class failed

    Thanks for your response, but this is either not an exact match or not matching the whole string, is there a way to be more specific?
    Also, I do have 80,000 rows, so if I could do this with a macro as opposed to a formula that would be great.
    any ideas much appreciated.
    thanks!

  14. #14
    Valued Forum Contributor
    Join Date
    08-06-2013
    Location
    Detroit, Michigan
    MS-Off Ver
    Excel 2013
    Posts
    671

    Re: error 1004 replace method of range class failed

    Here, try this
    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    06-01-2014
    Posts
    8

    Re: error 1004 replace method of range class failed

    This looks amazing!
    It works really well on the edited sample file, but I think I might need to edit it slightly for use in my full scale real file, where my data to be replaced is in column f of sheet "client'.
    Can you suggest where I can make this edit?
    Thanks so much!

  16. #16
    Valued Forum Contributor
    Join Date
    08-06-2013
    Location
    Detroit, Michigan
    MS-Off Ver
    Excel 2013
    Posts
    671

    Re: error 1004 replace method of range class failed

    In the loop, I'm matching column 1 to 1 and replacing 2 with 2. You can change those column numbers as needed.

    Sent from my SPH-D710 using Tapatalk

  17. #17
    Registered User
    Join Date
    06-01-2014
    Posts
    8

    Re: error 1004 replace method of range class failed

    Thanks for the help k64!
    So I'm trying to find the values in column F (6) and deliver the replacement value to column H (8 - is this even possible? it's an ideal but if it's not possibe that's ok)
    I've attempted the attached but it's erroring out:
    Please Login or Register  to view this content.
    any ideas?
    thanks so much!

  18. #18
    Valued Forum Contributor
    Join Date
    08-06-2013
    Location
    Detroit, Michigan
    MS-Off Ver
    Excel 2013
    Posts
    671

    Re: error 1004 replace method of range class failed

    UBound(arr1, 6) should be UBound(arr1, 1), which means "the upper bound of the 1st dimension (rows) or arr1.

+ 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. error 1004 AutoFill method of Range class failed
    By aritzel12 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-17-2013, 01:59 PM
  2. [SOLVED] error 1004 select method of range class failed
    By Lee_wwfc in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-23-2013, 12:34 PM
  3. Run-time error '1004' - Select method of Range class failed
    By g10drac in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-08-2011, 08:03 PM
  4. Runtime error 1004: Insert method of Range class failed......not sure why
    By welchs101 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-21-2011, 02:15 PM
  5. sort method of range class failed error 1004
    By droberts77uk in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-23-2009, 11:09 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