+ Reply to Thread
Results 1 to 88 of 88

Using Loops to find data

  1. #1
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Using Loops to find data

    I want to find some code that will search down a column until it finds one of a number of different words. when it finds one of the words it stops and deletes the row on which the word is contained. after deleting the data in the row, it continues searching down the column until it finds another of the words.

    for example......see work sheet attached,

    I want some code that will search down column B until it finds Sally or Robyn. As soon as it finds either of these names it stops and deletes all the data in that row and then continues searching down column B to find Sally or Robyn again........

    Is using a loop the best way to go with this???


    MOD: thread moved to parent Programming forum (VBA)
    Attached Files Attached Files
    Last edited by DonkeyOte; 02-04-2010 at 03:51 AM.

  2. #2
    Registered User
    Join Date
    07-23-2008
    Location
    Shanghai
    Posts
    11

    Re: Using Loops to find data

    Yes, you can use "for each... next" loop to achieve this.

    Additionally, IMHO, using advanced filter is much quicker if you're dealing with a bulk of data

    Regards,
    YM

  3. #3
    Forum Contributor vikas.bhandari's Avatar
    Join Date
    04-07-2006
    Location
    Delhi, India
    MS-Off Ver
    Office 2007 and 2010
    Posts
    303

    Re: Using Loops to find data

    The simplest option would be "filter down the data and then delete".

    Quote Originally Posted by yuanmin View Post
    Yes, you can use "for each... next" loop to achieve this.
    For each loop can be a constraint if you have multiple rows. If you have to do with programming, then findnext would be a better option.

    Copied the following code from Microsoft Help:

    Please Login or Register  to view this content.
    Thanks,
    Vikas
    Last edited by vikas.bhandari; 02-04-2010 at 04:13 AM.

  4. #4
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Using Loops to find data

    Hi,
    Filter and delete rows will be my choice. Here is code to do it:

    Please Login or Register  to view this content.
    Few notes - macro will create "headers" row and after that will delete it again. Add the words you want to search for in the array function.

    Buran
    Last edited by buran; 02-04-2010 at 04:27 AM.
    If you are pleased with a member's answer then use the Star icon to rate it.

  5. #5
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Using Loops to find data

    I'm very green on this.......do you replace the "c" with the name you want to find?

  6. #6
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Using Loops to find data

    As of the moment macro will search for John, Peter and Sally in column B and will delete the rows with this names. If you want to search for John, Peter and Greg for example, then the line will be

    Please Login or Register  to view this content.
    Please, note that edited my previous post to remove few things.

    P.S. Ops, I think you are talking to other member... Sorry

  7. #7
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Using Loops to find data

    cheers buran,

    that works perfectly.......

    In the "searchword" section. is there a way to search for part of a word in a field?

    for example you are looking for Robyn in a field but the field includes Robyn Smith....

    Also how do I cut and the paste "cellTypeVisible" with out cutting and pasting everything inbetween?

    cheers for your help
    Last edited by easty; 02-04-2010 at 05:10 AM.

  8. #8
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Using Loops to find data

    yes, you can use wildcards
    For example "Robyn*" will filter all records that start with Robyn

  9. #9
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Using Loops to find data

    what are a "wild cards"......how do I incorporate it into below

    SearchForWords = Array("John", "Peter", "Sally")

    don't worry I just figured it out.....
    Last edited by easty; 02-04-2010 at 05:16 AM.

  10. #10
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Using Loops to find data

    I need some help on how to cut and paste only "visible cells" though????

  11. #11
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Using Loops to find data

    Just a second - I noticed that it deletes one more row than it need to. I will answer to you shortly

  12. #12
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Using Loops to find data

    I'm affraid i messed something with the code when I edited my first post. sorry
    I think this works now correctly:

    Please Login or Register  to view this content.
    Last edited by buran; 02-04-2010 at 05:45 AM. Reason: Change to code

  13. #13
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Using Loops to find data

    easty.
    Please, note that I just edited the above code
    Please Login or Register  to view this content.

  14. #14
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Using Loops to find data

    hi Buran,

    Glancing at the OP's file, your use of
    Please Login or Register  to view this content.
    is fine in this context. However, there is the chance for errors/unexpected consequences if the macro was used on a data set that contains blank rows because it will only define the range as far as the blank row. I recommend explicitly defining the range to be filtered, eg
    Please Login or Register  to view this content.
    , which then also ties in with your later use of "usedrange".

    Rob
    Rob Brockett
    Kiwi in the UK
    Always learning & the best way to learn is to experience...

  15. #15
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Using Loops to find data

    Hi Rob,

    Thanks for your note. You are right - this is something I wasn't thinking about. Will have this in mind in the future. :-)

    Buran

  16. #16
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Using Loops to find data

    I'm using the new code you gave me

    Please Login or Register  to view this content.
    but for some reason it is not always deleting all the data required...........I've tried everything to figure out why but have no idea!! the old code seemed to work fine
    Last edited by teylyn; 02-10-2010 at 09:25 PM. Reason: added code tags

  17. #17
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Using Loops to find data

    If you are using the code from my post from yesterday, 11:40 AM, it works fine with the sample file. The code from my post 11:20, when running on sample file delete more rows than it have to, so you should not use it. The problem there was with the visible cells - I messed things when editing post.

    Anyway I made change to the code after broro183 remark about using autofilter when there are empty rows within data. Here it is:

    Please Login or Register  to view this content.
    I tested it with the sample file and it works fine. If you still have problems, you will have to provide more info in order to investgate it. Also you can check the entry that according to you must be delete and is not. For example it can have leading/trailing spaces andthis way it will be different from what you are searching for (unless you are using wildcard).

  18. #18
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Using Loops to find data

    That all works fine.

    I have attached a new file with some more detailed data.

    What I want to do now is set the data up as a filter and select "Equity Purchase" in column K.....then select "Jones Super Fund" in column C and copy and paste the "equity purchases" for this client to another worksheet.....then select the next client "Banks Superannuation Fund" and copy and paste the "equity purchases" for this client to another worksheet.....then select Smith Superannuation Fund and copy and paste the "equity purchases" for this client to another worksheet. and so and so on.

    the code you gave me before works well i just need to refine the filter to two variables now.

    cheers,
    Attached Files Attached Files

  19. #19
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Using Loops to find data

    hi Easty,

    Can you please upload a more detailed dummy file which contains the code you are currently using & also shows a "before & after" with explanation?

    If there are any further twists, can you please also include these in the post so we can be more effective & resolve your issues in less time?

    Rob

  20. #20
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Using Loops to find data

    thanks for your assistance Rob,

    see attached an updated file.......

    see Macro4 in the file.....would this be better/easier code to use than what is used in "Equity Purchase". The equity purchase macro just looks cleaner and easier to manage.

    thanks again for your help.....

    and yes the data is all dummy data.

    easty
    Attached Files Attached Files

  21. #21
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Using Loops to find data

    hi Easty,

    Sorry I may not get to this until the weekend, hopefully someone else can help you before then...

    If you want to try a few things yourself, you may find the below links useful:
    http://www.excelforum.com/excel-prog...ains-text.html
    http://www.excelforum.com/excel-work...orksheets.html
    & you may even get something from Stanley's post in http://www.excelforum.com/excel-prog...selection.html

    Goodluck
    Rob

  22. #22
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Using Loops to find data

    Hi easty,
    try this code:
    Please Login or Register  to view this content.
    I decided to make it in a way that will allow to search for multiple type of transactions. These are set in the SearchForWords Array. In the code I added also Accountancy fees
    It loops trough all clients and adds worksheet, than it change filter applied to the transaction type and copies each separate type of transaction.

    Buran

  23. #23
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Using Loops to find data

    that seems ok......but when it chooses accountancy fees the first client in the list doesn't have any accountancy fees...........it selects A2 and the xlDown goes all the way to the bottom of the worksheet and then xlRight to the right and copys the entire worksheet which doesn't have any data and pastes it to the clients worksheet......is there a way to skip this if there is no data available to copy?

  24. #24
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Using Loops to find data

    Hi,
    I iddn't hink that would be a problem. Here is the code:
    Please Login or Register  to view this content.

  25. #25
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Using Loops to find data

    it seems to get stuck at the code below.........

    Please Login or Register  to view this content.
    any thoughts?....................I've just run it and it looks good......if I step into the code and F8 it, it gets stuck but when you run macro it gets stuck for a moment then keeps going......cheers for that Buran!! I might come back to you if I have any more queries cheers mate you've been a bloody good help!!

    cheers
    Last edited by easty; 02-16-2010 at 05:16 AM.

  26. #26
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Using Loops to find data

    None. It works with the sample file. And I haven't changed it at all. The lines after Next i just set the column width of all sheets.

  27. #27
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Using Loops to find data

    at which line is the error (which line is higlighted)?

  28. #28
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Using Loops to find data

    If you change this line

    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.
    It will loop only trough columns in the used range and not all columns, but apart from that - no ideas.

  29. #29
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Using Loops to find data

    I think it just loops through that code a number of times before coming out of it.

  30. #30
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Using Loops to find data

    yes, but in my initial code it runs trough all columns, and it takes some time, so better use the changed one

  31. #31
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Using Loops to find data

    i think that new code works perfectly.......watch this space.

  32. #32
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Using Loops to find data

    Don't forget to mark thread solved, if it really is.

  33. #33
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Using Loops to find data

    hey Buran

    I don't want to delete the client's worksheet and insert a new one. I just want to retain each client's worksheet and insert the transactions at the bottom of previous transactions entered (if there are some) into their worksheet.

    I've tried to figure it out in your code but it is a bit technical for me.......its bloody good though!!

    does this make sense??
    Last edited by easty; 02-16-2010 at 11:07 PM.

  34. #34
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Using Loops to find data

    Hi easty,
    I just came in the office. I will change it in few minutes.

  35. #35
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Using Loops to find data

    thanks mate........

  36. #36
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Using Loops to find data

    Here it is
    Please Login or Register  to view this content.
    I also added few comments to explain what's going on.
    I tested it with the sample file, but test it carefully yourself too.

    Buran

  37. #37
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Using Loops to find data

    if there are no accountancy fees for a client.....it still selects A2 and xldown and xlright.......so copy and pastes the whole worksheet......

    if there is one accountancy fees it appears to copy and paste it 65310 times in the client's worksheet
    Last edited by easty; 02-17-2010 at 04:33 AM.

  38. #38
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Using Loops to find data

    Ops, my mistake - I haven't drink my coffee yet
    I took the previous code, not the one I cahnged yesterday. Will fix it now

  39. #39
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Using Loops to find data

    here it is

    Please Login or Register  to view this content.

  40. #40
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Using Loops to find data

    By the way - in the previeous code (where it doesn't check if anything left visible after the filter is applied), when there is accountancy fee, it copy it only once, not 65K times. At least with the sample file. Are you sure it copy it 65K times?

  41. #41
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Using Loops to find data

    I think if there is only one row of data in the filter and that data falls in row 1 (moving to row 2 after applying the filter) it copies that cell and all the cells down to the bottom of the worksheet.......it works fine if there is only one row of data and the row is not 1 (moving to 2)......

    sorry, I'm applying your code in another spreadsheet so it is probably bit difficult to interprit

  42. #42
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Using Loops to find data

    Hi easty,
    I checked this with the sample file and if there is only one row of data it selects only this one, not the entire sheet. I don't know why do you think the oposite. Did you went using F8 trough the code? And I still don't understand why is this a problem - even if it selects the entire sheet (It DOES NOT) there are only blank cells and nothing will be copied to the client sheet. and if there is another transaction after that, it will be added in the first blank row.

  43. #43
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Using Loops to find data

    Hi easty,
    I'm afraid i misunderstood you. You were right. When I checked it with the sample file it was only one row of data, but not on row 1. Here is a code that fix this (or at least what I understand is the problem):

    Please Login or Register  to view this content.

  44. #44
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Using Loops to find data

    is it possible to select Equity purchase and accountancy fees at the same time?

  45. #45
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Using Loops to find data

    yes, it is possible.
    easty, sorry, but I'm not able to work for you any more - I spent on this more time than I spent on my paid projects.

  46. #46
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Using Loops to find data

    hi all,

    Easty,
    I'll post a modified version of Buran's code sometime over the next couple of days (hopefully tonight) for you to review & then you can reraise any outstanding issues.

    Buran,
    I appreciate your openness about time spent, but this can be minimised. I (& I imagine, others) also appreciate that you are being open but not touting/pushing for paid business (btw, check the forum rules re your sig as it may be a bit "borderline").
    In line with some of the recommendations on the RentACoder site:
    - I recommend clarifying exactly what is required before starting to code & then testing code as you go before posting. we're all human but I think I have seen more than a couple posts where you apologise for an error in your suggestion which could probably have been caught with a proper once over.
    I'll try to comment the changes I make to your code so far so you can see my logic - of course it may not be better!
    - Push for an accurate/representative sample file to be uploaded right from the start (from memory, I think you've done that in this post).


    hth
    Rob

  47. #47
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Using Loops to find data

    @ broro183
    I'm not pushing for paid business at all. If this is what you (or someone else) understood from my last post - this is NOT the case. I'm spending time on this forum as I can learn a lot from more experienced from me and I'm willing to help if I'm able to do so. My last post was simply explanation, why I can not reply on easty's changing requests anymore. It wouldn't be nice simply to stop answering his posts, isn't it? This thread started as filter by one column, after that it turned to be two columns, single search term and working on this I suggested that it could be made in a way that allows for multiple words search. Now it turns to be something different. So I decided that I'm not able/willing to follow this thread anymore. Once again - I'm not pushing for, asking or whatever payment from easty. As a general remark - my understanding is that everyone is devoting as much time to this forum as he wants/can.

    Regarding my signature - when I added, there was no such rule #13, I checked. I think it was added few days ago 02-07-2010. If mods consider it violation of the rules, I will remove it. However - rule #13 is about "competitor forums" and I don't think my profile on freelance site is a competitor forum. I don't think it is different from a link to a homepage, for example.

    Buran

  48. #48
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Using Loops to find data

    hi Buran,

    I'm sorry, I didn't mean to come across all heavy but I posted rashly in haste. I agree that your communication approach was a good one & I was just intending to give some tips. I apologise, I had a bad day in the office & I let it come through in my post.

    I wasn't being sarcastic when I said "I appreciate that you are being open but (insert: replace with "and") not touting/pushing for paid business" - perhaps I should have worded it as "and" instead of "but". I DO appreciate your intent - in fact it was only from the link in your signature (in another thread) that I found out about Rentacoder's existence!

    Yep, your understanding is right, we give as much time as we want/can & I really hope that my abrasive post doesn't put you off. You've made some good contributions & it would be great to see you continuing to develop
    (I'm still learning too & hopefully we can share insights again)

    re the signature, I don't think that Mod's will ping you at all & I suspected that you wouldn't know about rule #13. I just thought I'd let you know because I feel the communication about the rule hasn't been as thorough as it should be...


    I've been taking a back seat on this thread because I didn't want to cut in. I can "tag team in" to see if we can get Easty as far as he wants to go...

    Apologies again,
    Rob

  49. #49
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Using Loops to find data

    Hi Buran and Rob,

    I woke up this morning to check Buran's reply and got a bit of a shock........I'm very new to this forum so sincerly apologise for maybe not using it as effectively and efficiently as I should.....

    Buran I greatly appreciate the time you have spent on this. The information you have given me has been fantastic and I apologise for changing course with the thread....Applying it to my spreadsheet raises a whole heap of new questions......and the code is well above my head so trying to adapt it to my spreadsheet is very hard if not impossible.

    Rob if you are able to continue assisting me, I'd be very happy. Otherwise I understand that the time spent on this query is a lot and you probably have others to help.

    Buran thanks again.

    Easty

  50. #50
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Using Loops to find data

    @ broro183

    No need to apologize, Rob. No offence here, really. :-) May be it was due to my non-native English, that I misunderstood you last night (and it was really late here). I'm glad that we made all this clear.

    Quote Originally Posted by broro183 View Post
    I really hope that my abrasive post doesn't put you off.
    It needs much more to push me away from the nice community here.

    Quote Originally Posted by broro183 View Post
    I've been taking a back seat on this thread because I didn't want to cut in. I can "tag team in" to see if we can get Easty as far as he wants to go...
    Hey, no "private" threads here, I think :-) Will be glad to jump in and contribute again, if I can add anything to your code.

    Also, thanks for pointing me the new rule and for the link in your last posting. Even if my sig is not exactly "a violation", I will change it.

    @easty - don't let be shocked so easy :-)

    Buran

  51. #51
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Using Loops to find data

    hi all,

    Buran, I'm pleased you're not easily put off

    Here's the best I have (see next post), without going back & rereading the entire thread. I've had a go at commenting the code/changes & once Easty has an understanding of it, he can probably delete half of the comments...

    I've separated some code out into functions (or copied & pasted functions that I have previously used) to prevent duplication & because you may be able to use it in other coding tasks.

    I think it is important to identify what all data is to prevent any ambiguity so I have added in the HdrArr which can be edited to provide the name of the header cells for each column. With this in mind, I have removed the deletion of the inserted header row, & I also copy it in to each of the Client sheets as they are created. Easty, you can amend HdrArr as necessary, provided you put everything inside double appostrophes & separate the strings with a comma & space. If your SearchForWords list becomes much larger I'd move it from the defined VBA array & into a separate list sheet in the spreadsheet, which can be grabbed (like the client names) & iterated through.

    I'm sure I've missed some points so please fire away with questions etc
    Also please note that at the moment the code will re-insert a new (or second) header row if you rerun the macro on the same dataset.

    see next post...


    hth
    Rob
    Last edited by broro183; 02-19-2010 at 09:40 PM.

  52. #52
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Using Loops to find data

    Here's my thoughts on the code...

    Please Login or Register  to view this content.
    hth
    Rob

  53. #53
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Using Loops to find data

    Hi Rob,

    There seems to be an error at

    Please Login or Register  to view this content.
    it says that "Subscript out of Range"

    Cheers

    Easty

  54. #54
    Forum Expert
    Join Date
    06-25-2009
    Location
    Sofia, Bulgaria, EU
    MS-Off Ver
    Excel 2003-2013
    Posts
    1,290

    Re: Using Loops to find data

    Hi easty,
    in his code Rob assumes that you have sheet named "Main". Rename the sheet where all clients data are to "Main"

    Buran

  55. #55
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Using Loops to find data

    oh......

    that was pretty simple!!

    cheers,

  56. #56
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Using Loops to find data

    Ooopps, my mistake!
    (I'm sure I saw that somewhere in the thread?)


    Thanks Buran :-)

    Easty, does it work on your real data?
    & more interesting for me - can you notice any difference in speed?
    If you're happy, can you please mark the post as solved?

    Rob

  57. #57
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Using Loops to find data

    Thanks Rob,

    How do I delete the headers and deactivate the filter at the end of the macro? I've tried a few different things but it always comes up as an error.

    Also, with the spreadsheet I'm applying this to, it doesn't seem to capture all the clients in column C. I've manipulated the data to decrease the rows and then they seemed to get captured. Is there a limit to the amount of rows the macro searches down column C to find new clients?

    Also, again with my spreadsheet, it doesn't seem to capture the "accountancy fees", only the equity purchases.

    I certainly can notice the difference in speed......is there a general code I can use to apply to other macros to make it speed up?

    Cheers Rob

    Easty
    Last edited by easty; 02-24-2010 at 12:29 AM.

  58. #58
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Using Loops to find data

    hi Easty,

    Quote Originally Posted by easty View Post
    How do I delete the headers and deactivate the filter at the end of the macro? I've tried a few different things but it always comes up as an error.
    I recommend keeping headers as it makes the data more auditable & removes much more potential for ambiguity. To remove them from the "Main" sheet try changing this section near the bottom of the code:
    Please Login or Register  to view this content.
    Quote Originally Posted by easty View Post
    Also, with the spreadsheet I'm applying this to, it doesn't seem to capture all the clients in column C. I've manipulated the data to decrease the rows and then they seemed to get captured. Is there a limit to the amount of rows the macro searches down column C to find new clients?
    Hmmm, no there shouldn't be a limit. Is the entire range selected if you change
    Please Login or Register  to view this content.
    Quote Originally Posted by easty View Post
    Also, again with my spreadsheet, it doesn't seem to capture the "accountancy fees", only the equity purchases.
    hmmm
    It worked in the sample file for me. Can you please upload a new sample file with the latest code included?
    Also, can you please identify the rows on the Main sheet with "accountancy fees" that don't end up where you expect them to be after you run the macro?


    Quote Originally Posted by easty View Post
    I certainly can notice the difference in speed......is there a general code I can use to apply to other macros to make it speed up?
    Cool, optimising for speed before having a working product is not really the best way to do it - but it still gives me a buzz!

    The main changes I made that improve the speed are commented in the code ie removing any ".select" & ".activate", and decreasing the amount of times information is pulled from a cell to be used in the VBE or pushed back into the spreadsheet. Also, the use of the "ToggleRefreshApp" sub improves the execution speed. It improves the speed because: turning off screenupdating stops Excel from "repainting the screen"; turning off calculation stops Excel trying to recalculate each time the autofilter is changed (depending on your version) & turning off events can stop other Excel macros/actions from trying to interrupt (I think this is unlikely in this case). You could use this sub at the start & end of other macros to help speed them up, as long as you aren't relying on the results of a calculation (or an event - eg refreshing a pivot table) in the macro.

    Have a read of this thread (http://www.excelforum.com/excel-prog...id-in-vba.html), some knowledgeable people have put in some words of wisdom. If you look at this thread, make sure to read more than one post (around the post describing the technique you want to use) because some points are rebutted - esp mine!
    As I say, I'm still learning

    hth
    Rob

  59. #59
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Using Loops to find data

    I've tried it all out and tinkered with it a bit and it all seems to work very well!!.......

    I would like to use the same code to select different data from the "Classification2" column and copy and paste it to a different column (column J for example) in each of the client's worksheets.

    I can't figure out where in the code it selects the client's worksheet and then finds the cell in the worksheet to paste the data specific to that client from the Main worsheet.

    Essentially, I would like to paste different data from the main worksheet into the client's worksheet in a different column of the client's worksheet.

    I am very close to finishing what I want to achieve.

    Thanks so much for your help Rob!!! it has been fantastic.......and Buran too!!

    Easty
    Last edited by easty; 02-24-2010 at 11:58 PM.

  60. #60
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Using Loops to find data

    hi Easty,

    Yay, I'm glad we are getting closer!

    We'll achieve what you want to achieve but now is the time to be very explicit in describing what else you want to happen.
    Can you please upload a new sample file with the latest code included*?
    Can you please also include "before & after" examples & clear explanation of the logic behind the results?
    *Have the working code identified & if you have problems with the below suggestions, you could store the attempted code in another module. To name the modules in the vbe, click on the module in the Project Tree on the left & press [F4] to bring up the Properties where you can change its name.

    Quote Originally Posted by easty View Post
    I would like to use the same code to select different data from the "Classification2" column and copy and paste it to a different column (column J for example) in each of the client's worksheets.
    Include this in the sample file. btw, you can change the headers to what they actually are, by changing the words in the "HdrArr" line of code. To do this, just change the words within the appostrophes & be sure to separate them all by a comma & a space.

    Quote Originally Posted by easty View Post
    I can't figure out where in the code it selects the client's worksheet and then finds the cell in the worksheet to paste the data specific to that client from the Main worsheet.
    Essentially, I would like to paste different data from the main worksheet into the client's worksheet in a different column of the client's worksheet.
    The below bolded section of code shows what makes the copying occur & the non-bolded section shows where it is being copied to (ie destination).. The bit that starts with a dot (".cells(..." is referring/relates to the object in the previous (still "open") With statement which is "With wsTarget". "wsTarget" is defined shortly before that.
    Please Login or Register  to view this content.
    To break it down to column by column copying you will need to adjust the start of the above line of code from
    Please Login or Register  to view this content.
    On an aside, if there is too much copying into different areas your macro will become slower & it would probably be more effective to modify the layout of your Main sheet. This means that the changes only need to be made once (before the filter & copy to separate sheets), rather than repeatedly for each sheet. Does that make sense?

    hth
    Rob

  61. #61
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Using Loops to find data

    Hi Rob.

    My wife had a baby boy over the weekend so I haven't been able to respond to your reply.

    I will put together a final post including a sample file and outline exactly what I want to achieve so we can knock it on the head

    Sorry I didn't respond to you sooner.......I have had a bit on my plate.

    Cheers,

    Easty

  62. #62
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Using Loops to find data

    Congratulations!
    I hope everyone's well...

    I'll glance at this thread occasionally, but when you do pop up a new post it may pay to p.m. me a link to the new post to remind me.

    Rob

  63. #63
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Using Loops to find data

    Hi Rob,

    Please see attached the spreadsheet which I hope will give you a clearer idea of what I’m trying to achieve.

    I’ve used a before and after worksheet for the “Smith Super Fund” as an example (Smith Super Fund = before and Smith Super Fund 1 = after).

    So the first step is to copy and paste (from Transaction Type 2 – column G) the “Equity Purchase”, “Equity Sale”, “Bonus Issue” and “Rights Issue Takeup” for the Smith Super Fund (as the Master Name) to the Smith Super Fund worksheet. I only want to copy and paste the data as shown in the Smith Super Fund worksheet (Account Name, Date, Narration and Amount) not the other irrelevant data. Ideally I would like the most recent transactions to be pasted at the top of the worksheet. Pasting it at bottom them sorting by date – newest to oldest is probably a lot easier.

    The next step is to copy and paste “Other Outgoings(Non-Asset Related)”, “Addition of Funds to Account” and “Accountancy Fees” to the Smith Super Fund worksheet. This is a bit trickier as we need to insert a column at Column I first, then copy and paste the formulas from cells J8:J11 (relating to December 2009) across to cells I8:I11, then paste the above data into Capital Flows section of the worksheet. We could also probably paste it at the bottom and then sort by date to make it easier. I need to be able to include the new month in the formula in cells “H1”, “H2”, “H3”, “H4”, “H5” and “H6” and then add one month to cell “H12”.

    That is pretty much it I think.

    I hope it all makes sense.

    Cheers Rob

    Easty
    Attached Files Attached Files
    Last edited by easty; 03-10-2010 at 09:28 AM.

  64. #64
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Using Loops to find data

    hi Easty,

    I have a few questions:
    - Are you happy for the file to contain a Template sheet which holds the layout & the required formulae for each created sheet?
    - How is the "PTF Current Value" populated?
    - I haven't used financial formulae for the past 10 years & am quite rusty with them. Is there any alternative to the Power formulae in H1:H6 which will allow for a range to be entered*, rather than each cell individually (& still achieve the same result)?
    *it could then be easier to achieve the inclusion of new columns.
    - After 12 months of data, won't the formulae in H1:H6 need to be changed for each yearly mile post?
    - How often will the file be renewed?
    eg, every year or will it be ongoing once the design is finalised?
    (there are only 256 columns in Excel 2003 which does allow for 21 years of monthly data, but inserting the columns will upset the print area on each sheet)
    - Will there only ever be one month of transactions in the Main sheet?
    - Once the macro is run, do you want the info removed from the Main sheet to prevent it being run twice?

    Rob

  65. #65
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Using Loops to find data

    hi Easty,

    When looking in slightly more detail (checking for unique values) I see that the below Type2 Transactions are not being copied to either the first section or to the "Capital flows" section. Can all these values/lines be ignored?

    "Unit Trust Distribution", "Convertible Note Interest", "Dividend Received", "Increase Total Number of Units", "Miscellaneous Interest", "Portfolio Management Fee", "Purch Shares - new issue/float", "Custody Fee", "PCMF/CTFE Interest", "Final Return of Capital", "Write Out Asset", "Write-In - Actual Units", "Asset Amalgamation", "Term Deposit Purchase", "Dividend - DRP", "RIGHTS ISSUE", "Adjustment Acquisition Cost", "AMALGAMATIONS/RECONST'N/SPLITS", "Rights Entitlement", "RI PAYMENT OF CALL MONEY"

    Rob

  66. #66
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Using Loops to find data

    Rob,

    Answers below

    - Are you happy for the file to contain a Template sheet which holds the layout & the required formulae for each created sheet? Yes....is this if a new client worksheet needs to be generated? If so, that's perfect.
    - How is the "PTF Current Value" populated? The portfolio current value is taken from a seperate set of data. I was somehow going to incorporate a lookup formula and then a copy and paste into the macro
    to update this number for each client.......do you have any suggestions. I have included an updated spreadsheet which shows how the portfolio data looks.....see Sheet1


    - I haven't used financial formulae for the past 10 years & am quite rusty with them. Is there any alternative to the Power formulae in H1:H6 which will allow for a range to be entered*, rather than each cell individually (& still achieve the same result)?
    *it could then be easier to achieve the inclusion of new columns.

    There isn't a formula that I know of unfortunately. Could you not just have the selected cells in the formula as absolute, so when you insert a row the formula doesn't change?

    - After 12 months of data, won't the formulae in H1:H6 need to be changed for each yearly mile post? Similar answer to before.....could we not just include 12 selected cells for 1 year, 36 for three etc....see updated spreadsheet....the number in H12 will just be the number of months since the portfolio's inception.

    - How often will the file be renewed? the file will be updated monthly.

    eg, every year or will it be ongoing once the design is finalised?
    (there are only 256 columns in Excel 2003 which does allow for 21 years of monthly data, but inserting the columns will upset the print area on each sheet)

    21 years will be enough for probably another 10 years.......at which time hopefully I will not be the one worrying about this problem...

    - Will there only ever be one month of transactions in the Main sheet? Yes, there will only ever be one month of transactions

    - Once the macro is run, do you want the info removed from the Main sheet to prevent it being run twice? Yes

    In response to your second question…..they probably can, however there may be times when I need to identify what transaction I’m looking for by locating it in that column…..i can’t give an example now, I just thought I’d try and retain some flexibility.

    Cheers Rob,

    Any questions please ask

    easty
    Attached Files Attached Files

  67. #67
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Using Loops to find data

    Hi Easty,

    Sorry I've been distracted, I'll have a test file up for you some time tomorrow (UK time).

    Updating the Power formulae is the tricky one at the moment. Would you be happy with it stating something along the lines of "Not Applicable" if that particular number of month's data doesn't yet exist for the particular fund?

    Rob

  68. #68
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Using Loops to find data

    that sounds fine.......could you not have an if function inbuilt into the formula so if there is not enough months nothing comes up.

    cheers

  69. #69
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Using Loops to find data

    hi Easty,

    I think the attached file will do almost everything you're after...
    I haven't fixed the Power formulae & I'm not sure if the current logic is correct!?
    I've created a test sheet with some variations & references as I tried to figure it out but I couldn't make it easy by referencing just one or two cells. If the existing logic is correct (with one cell reference for each month), it is a painful way of creating a formula for 10 years of monthly data - perhaps this could be the topic of a new thread...).

    I've changed the filtering to use a Helper column which is now based on two dynamic lists on the Reference Table sheet (ie add a transaction phrase to one of the lists & it should be copied to the client sheet when the macro runs). All new sheet creation is based on the Template (nb: power formulae need fixing) & adds them in order of their appearance in the data list. If you want the sheets sorted alphabetically, a quick google search should point you in the right direction.

    Sorry I haven't documented the file at all, but have a play & hopefully you'll learn more from working through it.

    Let mw know if you have any questions - I have my fingers crossed that it's reasonable because I've run a couple of tests & it seems to work.

    After running the macro (from the button on the Data sheet), I have manually copied the data from the Backup back onto the Data sheet before re-running it.

    hth
    Rob
    Attached Files Attached Files

  70. #70
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Using Loops to find data

    thanks for that Rob,

    It may take me some time to work through what you have done.....it looks very complex.

    i'll ket you know how i go.

    cheers

  71. #71
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Using Loops to find data

    hey rob,

    a couple of things....
    1. the incorrect transaction seem to appear in the client's capital flows and equity transactions...... after I run the macro it appears as though the formula in column H in the Transaction Data Input worksheet is referencing the incorrect row in column G....the formula keeps referencing three rows up in column G.

    2. why does the macro stop when it gets to Smith Super Fund.....see code below.

    HTML Code: 
    Cheers,

    Easty

  72. #72
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Using Loops to find data

    hi Phil,

    Are you getting much sleep with your little one?

    1. I'm sorry, I'm not sure how that happened, but you spotted it - can you fix it?
    Just kidding (see attached file) ;-)
    2. Again, sorry, I meant to comment that line out. The purpose for having the test in the code was to allow me to run the code "automatically" until it was upto the Smith client. When the code stopped at this point, it allowed me to step through the code one line at a time using the [F8] key.

    I've added some comments to the header cells in the attached (version 6) file for the Ref Table sheet, added an extra test at the start of the button macro & added comments for the Helper column. btw, I have absolutely no idea why I put so much complexity into the Helper column's formula in version 5, and I have simplified this in v6.

    hth
    Rob
    Attached Files Attached Files

  73. #73
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Using Loops to find data

    Hi Rob,

    Phil.....where did you get that from?? Its Peter......or easty

    We are very close to getting this sweet!!

    but, when I run the macro (from pressing "Press to split the monthly data" button on the "Transaction Data Input" tab I'm assuming). it still copy and pastes the incorrect transactions to each client.

    once running the macro, all the data from the "Transaction Data Input" tab is deleted (so I can't check to see whether the lookup formula's are referencing the correct rows), but the "Transaction Data Input (Backup)" tab, the lookup formula in column H is referencing the incorrect row (only two cells above where it. Does the marco include this tab?

    Cheers Rob.

    Easty

  74. #74
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Using Loops to find data

    hi Easty,

    Sorry - I'm not sure where I got the "Phil" from!

    Try the below...
    Please Login or Register  to view this content.
    The "... (Backup)" sheet is deleted (if one already exists), then recreated by making & renaming a copy of the "... Input" sheet. The contents are then deleted off the "... Input" sheet, to prevent the macro being run twice on the same data set. This backup of the data allows for all the details to be available for any extra investigation.

    Hopefully, I've got it right this time - at the moment, I'm certainly not living up to my past recommendations of testing code soundly first!

    The main issue that I haven't attempted to overcome is changing the Power formulae on either the template sheet or existing Fund's sheets.

    hth
    Rob

  75. #75
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Using Loops to find data

    just a small question Rob,

    the date in cell I21 in the template is referring to a named cell (=month of report), when you roll to the next month it continues to be linked to the same cell and is therefore not the correct date.....it is the same date as the new month.

    is there a way to copy/paste special and hard code that date before rolling to the next month or copy and paste special at the end of the macro.

    I hope this makes sense because I'm confusing the crap out of myself!!

    cheers

    Rob

  76. #76
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Using Loops to find data

    Hi Easty,

    Do you mean cell I16?

    Yes, you're making sense
    Try this one out...

    It makes use of a reasonably common way of hardcoding eg
    Please Login or Register  to view this content.
    - see if you can spot it in the code ;-)

    hth
    Rob
    Attached Files Attached Files

  77. #77
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Using Loops to find data

    another thing Rob,

    For every month going forward, I want to update all client's worksheets whether they have "capital transactions" or "equity transactions" or not...... as I want to be able to update their portfolio values in cell I7 each month.

    I've just been testing it with a lot more data and this is something that stands out as a risk......

    I hope this is an easy fix.

    I've tried the new hardcoding code for the date and the portfolio value.......for each client the "template's MT value" is hardcoded....not the MT value specific to each client. I've stopped the code just before it calls InsertColAndOrHardCode(ClientSht, False).....and the cell B1 in the client's worksheet isn't updated......I've checked that the formulas in excel options is on auto updated, but it still doens't seem to work.....any thoughts?.........don't worry mate, i worked it out. I put a range("b1").calculate straight before it calls the InsertColAndOrHardCode(ClientSht, False), and it works a treat!! sweet!!!
    Cheers mate
    Last edited by easty; 03-30-2010 at 05:42 AM.

  78. #78
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Using Loops to find data

    hi Easty,

    Sorry about the slow response. I'm not sure if I understand correctly, so, if the below code changes to the FilterAndCopyToSeparateClientShts macro (near the end) don't work, you may need to explain further...

    Please Login or Register  to view this content.
    It seems there may be some changes to your file layout ie "portfolio values in cell I7" is different from the v8 file which uses cell I8. So, if this suggestion doesn't work, can you please upload a new sample file with the new layout (& ideally, only the code that is currently being used)?


    re the hardcoding - yeah, solved!
    That's great :-)


    hth
    Rob
    Last edited by broro183; 04-08-2010 at 07:40 PM.

  79. #79
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Using Loops to find data

    Hi Rob,

    I inserted your code, but there seems to be an error.

    Please see attached file.....

    I have inserted the code below where the error occurs.

    Please Login or Register  to view this content.
    I don't know whether the code works or not at this stage.

    Basically - In the attached example, client = "Simon", wouldn't have a spreadsheet created for them because all transactions for this client are ignored (in column H) in the Transaction Data Input sheet. However, I need to have a speadsheet created so we can keep track of their portfolio value as shown in Cell I13 for clients. All clients need to have the portfolio value updated each month.......even if all transactions are "ignored.

    I hope this is a bit clearer......cheers mate, no rush on the response.

    Easty
    Attached Files Attached Files

  80. #80
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Using Loops to find data

    hi Easty,

    I've made a few changes (scattered throughout the code & worksheets) which I've tried to document on the Notes sheet. Also, while trying to test I've come across an error which won't let me delete the "Backup" sheet before repopulating it, but I think that is more due to something in my actual Excel setup (than it is to the file). Hopefully you won't get the same "can't enter break mode" error as I'm currently getting...
    There may be other changes needed but I'm off to bed now

    btw, when you are debugging code & a line highlights in yellow, you can press [ctrl + L] to identify any macros which precede the highlighted one. This is how I found out where the "ws" worksheet wasn't being defined prior to the "InsertColAndOrHardCode" sub being called.


    hth
    Rob
    Attached Files Attached Files
    Last edited by broro183; 04-12-2010 at 07:31 PM.

  81. #81
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Using Loops to find data

    Hi Rob,

    We are getting pretty close to finishing I think.

    See attached another sample file.

    I have included transactions for 11 different clients for the months of October 09 to March 10. I have also included the client's portfolio values at the start of each month. This info is in the "Transactions and Port. Values" sheet. I have run the macro for months Oct, Nov and Dec. A couple of issues have arisen, these are;

    - At the end of the macro, an error report comes up saying "Object doesn't support this property or method"......
    There are some issues with individual clients
    - Client Peter and Simon have had two November columns inserted and the initial portfolio value for October hasn't been captured.
    - Client Anthony appears to have worked ok
    - Client Banks has had two November columns inserted.
    - Client Jimbob appears to have worked ok
    - Client Archie didn;t have a November column inserted
    - Client Sun appears to have worked ok
    - ClientCousins didn't have a December column inserted
    - Client Bob has had two November columns inserted
    - Client Happy and Sad appears to have worked ok

    You can use the transactions in "Transactions and Port. Values" to roll forward through each month to see whether it works.....

    Cheers Rob

    Easty
    Attached Files Attached Files

  82. #82
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Using Loops to find data

    hi Easty,

    I'll try & look at this tomorrow...
    - I'm getting a similar "object doesn't..." macro error too & may even start a new thread to see if someone can explain what's happening. I think it relates to either VBE, [alt + t + o], & unticking "Require variable declaration" (not what I want to do!) OR possibly VBE, [alt + t + r] relating to "Microsoft excel 12.0 Object Library" as I appear to have two references to files in different locations

    Keep testing at your end & you may solve it before I get back to it. If you have access to a printer (I don't), I suggest printing out the code & seeing if you can spot any flaws in the logic...

    Rob

  83. #83
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Using Loops to find data

    hey Rob,

    I'll do my best to pick through the code.......but i don't understand it at all!! I understand small bits and pieces.....but not a lot.

    I'll let you know how I go.

    easty

  84. #84
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Using Loops to find data

    Hi Rob,

    Just thinking about it......would it be easier if all client's spreadsheets were already in the spreadsheet and the macro didn't have to insert a new sheet for a client? This would then mean the same action would be applied to every client's spreadsheet......the macro doesn't have to think about whether the sheet is an inserted sheet or if it has been there previously.

    I tried to look through the code but sorry mate its straight over my head.

    Cheers,

    Peter

  85. #85
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Using Loops to find data

    hi Easty,

    It may be easier, but we pretty close, so I'll carry on. Also, we can still have a different repsonse based on the existence of any transactions for the current month, so I'll just try & get the logic right.

    Sorry, I'm taking so long. We are down to the tough bit now - where there are diminishing returns & I'm finding it harder to focus on the code. I may try to print it out tomorrow & follow it through on paper.

    Rob
    Last edited by broro183; 04-19-2010 at 08:40 PM. Reason: grammar

  86. #86
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Using Loops to find data

    hi Easty,

    I may have cracked it!
    Not prettily, but hopefully cracked
    Can you please check out the attached & let me know if you spot any errors?

    hth
    Rob
    Attached Files Attached Files

  87. #87
    Registered User
    Join Date
    12-02-2009
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2007
    Posts
    83

    Re: Using Loops to find data

    hey Rob,

    Sorry I haven't responded to you sooner.......been very busy.

    I've worked through version 12 and yes I think you have cracked it!!!! you're a bloody legend!

    I'll try and work through it a bit of detail over the coming week to see if there are any issues/queries.

    I'll let you know.

    Thanks so much for helping me out with this.....this forum is unbelieveably useful!!!

    easty

  88. #88
    Forum Expert
    Join Date
    01-03-2006
    Location
    Waikato, New Zealand
    MS-Off Ver
    2010 @ work & 2007 @ home
    Posts
    2,243

    Re: Using Loops to find data

    Cool, I have my fingers crossed

    How's the new baby, are you getting any sleep?

    Rob

+ 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