+ Reply to Thread
Results 1 to 32 of 32

A complex problem-replacing repetitive numbers with blank

  1. #1
    Forum Contributor
    Join Date
    04-09-2012
    Location
    Montreal, Canada
    MS-Off Ver
    Excel 2007
    Posts
    117

    A complex problem-replacing repetitive numbers with blank

    Dear All, once again thanks for reading and trying to help. Its one of the most wonderful forums I have been to!
    I'm attaching a mini replica of the excel file I have. As you will see, there are company names in the first row and company codes below each name. Its a time series daily data for 30 years. Now, here is the problem. For some companies (those which say 'dead' after the company name-for example column F company, ABN Granites), after a certain date (in the case of ABN granites, its 17-02-1997) the values are repeated till the end (again in the case of ABN granites, that value is 5.56 which starts at around the same date-17 feb 1997). There are few other companies in this file which are dead and have the same issues after a certain date.
    In the original sheet-and I have many such sheets-, there are approx 200+ companies which either have the word, dead or the word, susp, which has the same issue. Is there a way I can tell excel to replace all such numbers after a particular date with a blank? Manually doing it one by one will take hours if not days!
    Please let me know if you want more information on this problem.
    Thanks very much!
    Attached Files Attached Files

  2. #2
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: A complex problem-replacing repetitive numbers with blank

    Are the dates always part of the column title and in the same format mm/dd/yy?
    A macro can do this.
    Pierre Leclerc
    _______________________________________________________

    If you like the help you got,
    Click on the STAR "Add reputation" icon at the bottom.

  3. #3
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: A complex problem-replacing repetitive numbers with blank

    Try the following macro:
    Please Login or Register  to view this content.
    It will work on the active sheet.

  4. #4
    Forum Contributor
    Join Date
    04-09-2012
    Location
    Montreal, Canada
    MS-Off Ver
    Excel 2007
    Posts
    117

    Re: A complex problem-replacing repetitive numbers with blank

    Wonderful! Thanks so much! Yes, it worked on the active sheet. Yes, the dates are always the part of the column title and in the same format-which is bit different from the format in the time series dates. So, will this macro work on much larger data sets? Also, if I want to include the word, 'susp' where should i put it in the macro? Some companies have susp in the column title instead of dead and they have the same issue.

  5. #5
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: A complex problem-replacing repetitive numbers with blank

    It will works on any data set. Larger is not a problem.
    To add the word "susp" in the condition, here is how to do it. This modified macro will prevent any bug if the words "dead" or "susp" are present in the name of a client while there is no date in the column title. The error will stop the macro.
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    04-09-2012
    Location
    Montreal, Canada
    MS-Off Ver
    Excel 2007
    Posts
    117

    Re: A complex problem-replacing repetitive numbers with blank

    Hi p24leclerc, unfortunately this macro doesnt seem to work on a larger data set with 250+ columns and same number of rows as I had in my example sheet. I mean it does the job for first few companies but after that, it completely misses replacing the repetitive numbers with blanks. Not sure what's the problem. I couldnt attach my sheet here because its much more than 1 mb limit, so perhaps if i can send you an email you can see the sheet.
    Thanks!

  7. #7
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: A complex problem-replacing repetitive numbers with blank

    see private message

  8. #8
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: A complex problem-replacing repetitive numbers with blank

    I realized there were missing dates in column A. I thought either all dates of years were present or that the dates in titles were dates present in column A.
    I modifiied the macro to take this into account.
    It leaves you to make sure there is a date when a company is marked DEAD or SUSP.
    I also added 2 message box to tell you when the macro was completed normally and when it encounters an error with the company name causing the error.
    Please Login or Register  to view this content.
    Hoping it is all right now.

  9. #9
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: A complex problem-replacing repetitive numbers with blank

    This might be a little faster

    Please Login or Register  to view this content.
    Last edited by mike7952; 02-26-2013 at 12:39 AM.
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: A complex problem-replacing repetitive numbers with blank

    Try this.
    Must be faster
    Please Login or Register  to view this content.
    Last edited by jindon; 02-26-2013 at 03:06 AM.

  11. #11
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: A complex problem-replacing repetitive numbers with blank

    Your missing on column G though!

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: A complex problem-replacing repetitive numbers with blank

    Quote Originally Posted by mike7952 View Post
    Your missing on column G though!
    Ignore this, if this one is talking about my code.

  13. #13
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: A complex problem-replacing repetitive numbers with blank

    Originally Posted by jindon Ignore this, if this one is talking about my code.
    Still wrong, even after editing your code... Column G Date is 05/02/01 which is 2/5/01. Below code starts at 12/31/2004 missing 3 years?

    Please Login or Register  to view this content.
    Last edited by mike7952; 02-26-2013 at 01:38 AM.

  14. #14
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: A complex problem-replacing repetitive numbers with blank

    maybe "$1/$2/$3" ("dd/mm/yy")

  15. #15
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: A complex problem-replacing repetitive numbers with blank

    You are totally worng.
    What I edited was just changed 0 to 1 for the 3rd arg for Match function, just in case for the date is missing.
    Nothing to do with the original algorithm.

    ColG says "05/02/01" that means 2001/Feb/05.
    See row 7333 which is the date of 2001/2/5 after the code.
    The code attached to the attached file is the code before I have edited, so it is 0, instead of 1 for 3rd arg of Match function and it is still functioning.
    Attached Files Attached Files

  16. #16
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: A complex problem-replacing repetitive numbers with blank

    perhaps it depends on the regional settings
    it
    Please Login or Register  to view this content.
    gives me
    17.02.1997
    01.02.2005 (instead of 05.02.2001)
    15.01.1999
    and "$1/$2/$3" gives the correct result

  17. #17
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: A complex problem-replacing repetitive numbers with blank

    Quote Originally Posted by nilem View Post
    perhaps it depends on the regional settings
    Maybe so, then OP should adjust it under his/hers regional setting.
    Anyway, the code should be like that simple when using RegExp.

  18. #18
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: A complex problem-replacing repetitive numbers with blank

    Hi nilem , Hi jindon,
    I got issues with both your macro. ABC macro runs real fast but it does not recognize all dates the same. Ususally, dates under 2000 are well interpreted but those above are wrongly converted.
    I was not able to run the other macro as it was not seing any company to process. It is about the pattern I think.

    To pahari75, you have to make sure the dates in the company names are present in the column A, otherwise the macro loops for a long time. My macro takes longer to run but I'm pretty sure of the results.
    Regards
    Last edited by p24leclerc; 02-26-2013 at 01:04 PM.

  19. #19
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: A complex problem-replacing repetitive numbers with blank

    Hi nilem , Hi jindon,
    I got issues with both your macro. ABC macro runs real fast but it does not recognize all dates the same. Ususally, dates under 2000 are well interpreted but those above are wrongly converted.
    I was not able to run the other macro as it was not seing any company to process. It is about the pattern I think.

    To pahari75, you have to make sure the dates in company names are present in column A otherwise the macro loops for a long time.
    My macro takes more time to run but I'm pretty sure you'll get good results.
    Last edited by p24leclerc; 02-26-2013 at 01:08 PM.

  20. #20
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: A complex problem-replacing repetitive numbers with blank

    Quote Originally Posted by p24leclerc View Post
    ABC macro runs real fast but it does not recognize all dates the same. Ususally, dates under 2000 are well interpreted but those above are wrongly converted.
    Does it not works correctly on the example workbook? If not can you upload an example of where its not working?
    Last edited by mike7952; 02-26-2013 at 01:25 PM.

  21. #21
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: A complex problem-replacing repetitive numbers with blank

    Hi Mike,
    I ran your ABC macro on sample book1 supplied by pahari75 in post #1.
    On column G, here is the company name "A C E LABORATORIES DEAD - 05/02/01 - TOT RETURN IND"
    Your macro returned 2005-02-01 as date. See attached file.

    About nilem macro, I had to make a small modification to the pattern as it was looking for a space after the date which is how dates appear in the sample workbook but in another file supplied by pahari75, dates are at the end of the company name so there was no space.Once modified, I must say its the fastest one and it is doing a perfect job.

    Here jindon's macro modified to accept dates at the end of company name:
    Please Login or Register  to view this content.
    I think it is the first time I see REGEXP used in response to a thread. I must say I don't look at them all.
    Thanks to all of you for this demonstration of REGEXP.
    Attached Files Attached Files
    Last edited by p24leclerc; 02-28-2013 at 07:37 PM.

  22. #22
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: A complex problem-replacing repetitive numbers with blank

    Your macro returned 2005-02-01 as date
    Glad you got it working. I agree Jindon code is much faster, but as far as the date on my cpu the date is 5/2/2001. So like Nilem said it must be a regional setting in excel.

    This works works for me
    Please Login or Register  to view this content.
    this dosent

    Please Login or Register  to view this content.
    Last edited by mike7952; 02-26-2013 at 04:26 PM.

  23. #23
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: A complex problem-replacing repetitive numbers with blank

    The forum is dedicated to sharing knowledge and information, not proving who is a better programmer. Please refrain from arguing when answering posts. If you have an issue with another poster, contact each other using Private Messages (PM).
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  24. #24
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: A complex problem-replacing repetitive numbers with blank

    Please Login or Register  to view this content.

  25. #25
    Forum Contributor
    Join Date
    04-09-2012
    Location
    Montreal, Canada
    MS-Off Ver
    Excel 2007
    Posts
    117

    Re: A complex problem-replacing repetitive numbers with blank

    My apologies guys, I was traveling, so didnt check the thread. Thanks to P24Lecrec for the PM. There seems to be many versions, let me go through each of the replies properly before I comment further.

  26. #26
    Forum Contributor
    Join Date
    04-09-2012
    Location
    Montreal, Canada
    MS-Off Ver
    Excel 2007
    Posts
    117

    Re: A complex problem-replacing repetitive numbers with blank

    Hello P24leclerc and others, I checked the macros and here is the problem:
    1. There are many companies in the actual sheet which are dead but there is no date listed. Even though there are repetitive numbers after a certain date, that date in not mentioned, so I'm not sure if there could be a solution to that.

    2. As noticed earlier, in the column A there are certain dates missing. So, for example if the top cell mentions date 02/03/1999 as the dead date, there is a possibility that the repetitive numbers start at 04/03/1999 as 02/03/1999 is missing. But I guess P24leclerc has already found a solution for that.

    3. As for the formats of the dates which you guys have already discussed a lot, I think it works fine, but we have to first find the solution for point 1 before we get to these issues.

    I think there are two ways to get around point 1.

    a) Either we first create a macro so that it could identify such dead companies with dates missing and highlight them or separate them. Then I manually give them dates so that macros above could run successfully. Ofcourse it will take some time as there seems to be quite a few such companies in each sheet.

    b) Or we could write a new macro where rather than having this complex macro with matching dates from dead companies etc, we simply write a program so that in the sheet all such companies when a number starts repeating and goes on till the end, it removes all such numbers. For example, we could write a program so that it takes into account that only when the number repeats more than 10-20 times and towards the end, it should replace such numbers with blank. The only problem with this approach is that at times, a company gets dead bit later than the date when the numbers start repeating. So, there will be some numbers deleted which ideally shouldnt be.

    My guess will be that b) should be easier to do, but I have to check with my boss if that's not a big compromise we are doing.

    Any thoughts on this? Thanks again for your help everyone.

  27. #27
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: A complex problem-replacing repetitive numbers with blank

    This will clear the cells from the bottom as long as the value is the same.

    Be careful, this doesn't care about the heading.
    Please Login or Register  to view this content.

  28. #28
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: A complex problem-replacing repetitive numbers with blank

    I think it could be done within the same macro. If the company name has DEAD/SUSP and a date, it is processed as required but if there is no date then the macro will remove but 10 of the repetitive data at the end of this company column.

    Here is how I did it:

    here is jindon macro modified with jindon today's macro to takes care of coimpany with the words DEAD or SUSP but without date in their names.
    I used the original jindon macro and added an ELSE statement to process company names without date in their name. I also added an IF statement to make sure this company have the word DEAD or SUSP in the name. If so, I used jindon today's macro to remove repeating numbers at the end of its column keeping about 10 repetitive data.
    Please Login or Register  to view this content.
    P.S.: jindon, I always learn a lot looking at your code.

  29. #29
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: A complex problem-replacing repetitive numbers with blank

    If the header always contains "Dead" or "sups", the code should look like
    Please Login or Register  to view this content.

  30. #30
    Forum Expert p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2021
    Posts
    2,081

    Re: A complex problem-replacing repetitive numbers with blank

    You're right. No needs to test the same thing twice.

  31. #31
    Forum Contributor
    Join Date
    04-09-2012
    Location
    Montreal, Canada
    MS-Off Ver
    Excel 2007
    Posts
    117

    Re: A complex problem-replacing repetitive numbers with blank

    Wonderful guys! Million thanks to both Jindon and P24leclerc! I checked the last macro provided my Jindon on a large dataset and it worked! I mean I randomly checked 8-10 companies and it has done the job. There is just one little thing-for companies where the dead date is not available corresponding the top cell date, the repetitive numbers are cut from a day earlier. I was wondering if the blanks could start from a day later? I mean if the dead date is 27th feb and there is no 27th feb on the A column, it starts deleting the numbers starting from 26th feb rather than lest say 1st march.
    Anyways this is a small thing. Thanks again!

  32. #32
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: A complex problem-replacing repetitive numbers with blank

    Try change
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

+ 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