+ Reply to Thread
Results 1 to 21 of 21

Adding 7 days to a date using macro

  1. #1
    Registered User
    Join Date
    02-25-2009
    Location
    Germany
    MS-Off Ver
    Excel 2000
    Posts
    12

    Adding 7 days to a date using macro

    Hi!

    It would be really great if you could help me with my macro that I am trying to create for my spreadsheet.

    Basically it's to make my content management easier.

    I have made a button and assigned a macro to it. At the moment the button creates a new column and makes it the right size etc.

    Please Login or Register  to view this content.
    However what I really want is for the newly created cell to take the date from the cell next to it and add 7 days to it. For example: 04.01.-10.01. (is the original date) and 11.01.-18.01. (would be the new date)

    Any kind of workaround(other way of formatting the date) or new logical process you have for doing what I want would be really great!

    P.S im using Excel 2000 (German version)

    Thanks in advance!

    -Ninjao
    Last edited by ninjao; 02-27-2009 at 07:33 AM.

  2. #2
    Valued Forum Contributor mudraker's Avatar
    Join Date
    11-10-2003
    Location
    Melbourne, Australia
    Posts
    3,983

    Re: Adding 7 days to a date using macro

    The macro code you posted needs a lot of cleaning up

    why are you copying cells c21:c30 to b21:30 then clearing b21:28

    In what cell is the 04.01.-10.01 entry
    Please Read Forum Rules Before Posting
    Wrap VBA code by selecting the code and clicking the # icon or Read This
    How To Cross Post politely

    Top Excel links for beginners to Experts

    If you are pleased with a member's answer then use the Scales icon to rate it
    If my reply has assisted or failed to assist you I welcome your Feedback.

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Adding 7 days to a date using macro

    Whilst cleaning the code, remove the unnecessary selections

    Please Login or Register  to view this content.
    Can be reduced to

    Please Login or Register  to view this content.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Registered User
    Join Date
    02-25-2009
    Location
    Germany
    MS-Off Ver
    Excel 2000
    Posts
    12

    Re: Adding 7 days to a date using macro

    Quote Originally Posted by mudraker View Post
    The macro code you posted needs a lot of cleaning up

    why are you copying cells c21:c30 to b21:30 then clearing b21:28

    In what cell is the 04.01.-10.01 entry
    Yeah I just posted the rough macro code I've already cleaned it up.

    The Cell that contains the date is: B21

    Will it be possible to do what I plan to do?

    Thanks!

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Adding 7 days to a date using macro

    Not sure what you want exactly, but something like
    Please Login or Register  to view this content.
    It's best to post cleaned up code, it's easier to follow.

  6. #6
    Registered User
    Join Date
    02-25-2009
    Location
    Germany
    MS-Off Ver
    Excel 2000
    Posts
    12

    Re: Adding 7 days to a date using macro

    Thanks for the quick reply!

    I just tried adding your code to my macro and I got the following error "Invalid Identifier" and it highlights the code "IsDate" (well the error was actually in german but thats what I translate it as)

    Here is my current macro:

    Please Login or Register  to view this content.

  7. #7
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Adding 7 days to a date using macro

    Looking at your code you clear contents in column B, so you can't add 7 days to any value there. In fact you copy C1 to C28 to B then delete it.

    What exactly are you doing?

  8. #8
    Registered User
    Join Date
    02-25-2009
    Location
    Germany
    MS-Off Ver
    Excel 2000
    Posts
    12

    Re: Adding 7 days to a date using macro

    Oops sorry you are correct it would be C21.

    I attached an image to illustrate what I imagine. Maybe it will make it clearer

    Here is a link incase the attachment doesn't work
    Attached Images Attached Images

  9. #9
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Adding 7 days to a date using macro

    The attachment does work, but a workbook would be more useful. Are you copying C to B & adding 7 days in B?

  10. #10
    Registered User
    Join Date
    02-25-2009
    Location
    Germany
    MS-Off Ver
    Excel 2000
    Posts
    12

    Re: Adding 7 days to a date using macro

    Yes, I'm copying C to the newly created, empty B. And then adding 7 days to B.

    I would add the workbook but it contains sensitive company related data

  11. #11
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Adding 7 days to a date using macro

    Try this
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    02-25-2009
    Location
    Germany
    MS-Off Ver
    Excel 2000
    Posts
    12

    Re: Adding 7 days to a date using macro

    That code did the following for me: It added a new column and then filled out the range B21:B29 with the following:

    Please Login or Register  to view this content.
    Damn I guess this one is quite hard. Do you have any other ideas how I might be able to achieve a similar effect? Maybe with a different Date Layout..?

    Thanks for helping me so far!

  13. #13
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Adding 7 days to a date using macro

    Attach a dummy workbook, the code adds a new Column B , * copies the dates in C adding 7 days. There must be dates in Column C.
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    02-25-2009
    Location
    Germany
    MS-Off Ver
    Excel 2000
    Posts
    12

    Re: Adding 7 days to a date using macro

    Thanks Roy, I see how your's works.

    I added a "basic" version of what I am working on(minus sensitive data) so you can have a better look at my problem. In the Excel file I have added additional info for you so you can see what my project is about and hopefully have a better understanding of what I'm working on!

    -Ninjao

    p.s. Woche hinzufügen means "Add week"
    Attached Files Attached Files

  15. #15
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Adding 7 days to a date using macro

    Your dates are text, you cannot add 7 days to a text entry

  16. #16
    Registered User
    Join Date
    02-25-2009
    Location
    Germany
    MS-Off Ver
    Excel 2000
    Posts
    12

    Re: Adding 7 days to a date using macro

    Yeah I figured as much.

    Damn I just can't get it to work

  17. #17
    Valued Forum Contributor squiggler47's Avatar
    Join Date
    02-17-2009
    Location
    Littleborough, UK
    MS-Off Ver
    Excel 3.0 to 2007+2010! (couldnt get 2.1 working)
    Posts
    1,013

    Re: Adding 7 days to a date using macro

    You could try these 2 functions :-

    They take "04.01.-10.01." and "01 / 2009" as arguments

    and

    return 11.01.-17.01 and 03 / 2009 respectively (weeknum used excels weeknum function, so it doesnt agree with yours but you can adjust)


    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Add this to your code in place of isdate....
    Please Login or Register  to view this content.
    Last edited by squiggler47; 02-26-2009 at 01:14 PM.

  18. #18
    Registered User
    Join Date
    02-25-2009
    Location
    Germany
    MS-Off Ver
    Excel 2000
    Posts
    12

    Re: Adding 7 days to a date using macro

    Wow thanks! That helped me a lot. It currently works... somewhat. The date does get the update. However I didn't add the week number function because for some reason it wouldn't execute at all.

    I also don't REALLY need the weeknumber counter...however when I try to press the button again to add a new week(just to test if it works again) I get an error:

    "Runtime error 13"

    and in the debugger it highlights this bit of code:
    Please Login or Register  to view this content.
    Here is my full macro, in it's current state:

    Please Login or Register  to view this content.
    Do you know what the problem might be?

    Thanks for the help so far guys!

  19. #19
    Valued Forum Contributor squiggler47's Avatar
    Join Date
    02-17-2009
    Location
    Littleborough, UK
    MS-Off Ver
    Excel 3.0 to 2007+2010! (couldnt get 2.1 working)
    Posts
    1,013

    Re: Adding 7 days to a date using macro

    Yes function needs 2 parameters dates in format "dd.mm.-dd.mm." and year "51 / 2008", if either of these is blank the function wont work!

    you can call the function :-

    Range("b21").Value = NextWeek(Range("C21"), Date$) to make it work using todays year!

    the second function didnt work, because dummy that i am didnt test it in excel 2000!

  20. #20
    Valued Forum Contributor squiggler47's Avatar
    Join Date
    02-17-2009
    Location
    Littleborough, UK
    MS-Off Ver
    Excel 3.0 to 2007+2010! (couldnt get 2.1 working)
    Posts
    1,013

    Re: Adding 7 days to a date using macro

    repaired functions :-

    You need to have both since you have the year and the date in 2 different cells, so both cells have to be updated

    I attached the worksheet which works on my copy of excel 2000

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

  21. #21
    Registered User
    Join Date
    02-25-2009
    Location
    Germany
    MS-Off Ver
    Excel 2000
    Posts
    12

    Re: Adding 7 days to a date using macro

    Oh wow thanks that works great!!


    Now on to the even harder stuff Importing data from a .csv !

+ 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