+ Reply to Thread
Results 1 to 16 of 16

Add comment in column if

  1. #1
    Forum Contributor
    Join Date
    12-19-2011
    Location
    Central Europe
    MS-Off Ver
    Excel O365
    Posts
    361

    Add comment in column if

    Hi all

    I need to create a list of open items each day

    In cell A2 the "as of date" is written. So e.g. tomorrow i'll make the list as of 1st October 2012 (it's entered in a proper excel date format), today its as of 28th September 2012

    In the list of open items the date is in col C
    After five working days from the as of date a comment for the item should be mandatory.
    Therefore i'd like to add this in a dedicated col. (e.g. col L)

    So i figured following code should


    Please Login or Register  to view this content.
    But it doesnt work.

    I know, I know... if formula would work - but theres other stuff linked to this - so it would make it easier if these items were updated automatically.

    Anyone who could hep out?

    Office 2007

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

    Re: Add comment in column if

    I'm not sure I understood everything. But I think this should do the job.

    Please Login or Register  to view this content.
    If you are pleased with a member's answer then use the Star icon to rate it.

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

    Re: Add comment in column if

    By the way if it always cell A2 then the line should be

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    12-19-2011
    Location
    Central Europe
    MS-Off Ver
    Excel O365
    Posts
    361

    Re: Add comment in column if

    Hi buran

    I tried your code, but it did not do what i expected

    basicly i need to follow open items - in this list if a line is older than 5 days a comment is mandatory

    In cell A2 always the last working date is entered (as of reference date)
    in col. C you can see the date the items has first been pending.

    So, if A2 as 25th Sept. 2012
    and C5 has 24th Sept. 2012
    so the diff is 1 day and no comment needed.


    So, if A2 as 25th Sept. 2012
    and C6 has 17th Sept. 2012
    so the diff is 8 days and comment is mandatory (in col. o) - so in col. P the word "COMMENT" should pop up.

    as I said, i could do it with formulas, but you know how it is - not properly copied by the user, etc, etc...

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

    Re: Add comment in column if

    Did you see my second post? My first impression was that you have the dates down in every cell in column A. Then I understood I'm wrong and post different line of code.
    can you upload sample workbook, because if dates are in proper excel date format it shoul work.. I assume you assign value to LR somewhere in your code, before the code that is here... Also you start the loop from row 1, but probably it starts at row 3 (because in A2 you have some "constant" value)... however I cannot know this, so I didn't change it. you know it better... Apart from this the code is workning:

    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    12-19-2011
    Location
    Central Europe
    MS-Off Ver
    Excel O365
    Posts
    361

    Re: Add comment in column if

    No, sorry, I didnt...

    OK great... that works
    quick question: if you disable screenupdating, does it update anyway? I have never experienced this before...

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

    Re: Add comment in column if

    Yes, it will update, but you will not see the "update" till macro end.

  8. #8
    Forum Contributor
    Join Date
    12-19-2011
    Location
    Central Europe
    MS-Off Ver
    Excel O365
    Posts
    361

    Re: Add comment in column if

    Hi buran

    That's what I meant - but for me the screen updates nonetheless.
    I never saw this before, any idea?

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

    Re: Add comment in column if

    mmm. no ideas at the moment

  10. #10
    Forum Contributor
    Join Date
    12-19-2011
    Location
    Central Europe
    MS-Off Ver
    Excel O365
    Posts
    361

    Re: Add comment in column if

    stupid me... i should disable events ;-))

    quick question: how would I intergrate this in a worksheet change, rather then a macro, which will run manually?

    Thanks

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

    Re: Add comment in column if

    put the code in the worksheet class module in Worksheet_Change event procedure e.g.

    Please Login or Register  to view this content.
    Last edited by buran; 10-03-2012 at 04:38 AM. Reason: fix the code

  12. #12
    Forum Contributor
    Join Date
    12-19-2011
    Location
    Central Europe
    MS-Off Ver
    Excel O365
    Posts
    361

    Re: Add comment in column if

    Hi

    Thanks - I actaully tried just that

    I've extended my code in the meanwhile

    Please Login or Register  to view this content.

    when i run the code as a single macro it works pefectly

    but when its on worksheet_change it ends in "Method 'Value' of object 'Range' failed"

    Any idea why this would happen?
    Thx

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

    Re: Add comment in column if

    I tried it and in my case it works without error. Note that in this case (with worksheet_change) and with the loop and several changes in the sheet, you actually run in very long loop...

  14. #14
    Forum Contributor
    Join Date
    12-19-2011
    Location
    Central Europe
    MS-Off Ver
    Excel O365
    Posts
    361

    Re: Add comment in column if

    Hi Buran

    Many thanks - it's functional for me as well now - allthough only after I copied all the code in a new workbook... strange..

    OK, one more question.
    So, my code fills in col. P based on the value of col. O (in the second part)
    --> But if a range in col. = O is merged (i.e. O7:O14) col. P will carry the wrong value.
    How can I get Excel, that when it makes the offset on C8, that it considers cell C7 instead?

    Thanks a lot


    PS: Yes, I know - avoid merging cells ;-)
    Last edited by FallingDown; 10-08-2012 at 06:07 AM. Reason: PS: Yes, I know - avoid merging cells ;-)

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

    Re: Add comment in column if

    You can use Range.MergeCells property to check if the cell is part of merged area. then you can take the value form the first cell in the merged area using Range.MergeArea property like this

    Please Login or Register  to view this content.
    In the example I work with fixed row (12), because i don' t have your current code. you can add this to a loop and change the row number...

  16. #16
    Forum Contributor
    Join Date
    12-19-2011
    Location
    Central Europe
    MS-Off Ver
    Excel O365
    Posts
    361

    Re: Add comment in column if

    Perfect! Helped me a lot

    Thanks

+ 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