+ Reply to Thread
Results 1 to 6 of 6

Using VBA to fill col with dates based on start and end date

  1. #1
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Using VBA to fill col with dates based on start and end date

    i have an example file see enclosed.

    In this file i have two dates. Start and End. I want to use VBA to fill a column from the start date to the end date (with each entry being the first of the month).

    Not sure the best way to do this.
    Attached Files Attached Files

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Using VBA to fill col with dates based on start and end date

    Did you read 'autofill' in the VBEditor's help ?



  3. #3
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Re: Using VBA to fill col with dates based on start and end date

    I am not sure i understand?

  4. #4
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Re: Using VBA to fill col with dates based on start and end date

    Based on snb's comment i guess they are suggesting i use auofill technique to solve this problem.

    So proceeding along this path i came up the following:

    Please Login or Register  to view this content.




    seems to work..................

  5. #5
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Re: Using VBA to fill col with dates based on start and end date

    Worked in my test file..........but when i run it in my main program i get this

    08/01/07
    09/01/07
    08/02/07
    09/02/07
    08/03/07
    09/03/07
    08/04/07
    09/04/07
    08/05/07
    09/05/07
    08/06/07
    09/06/07
    08/07/07
    09/07/07
    08/08/07


    very strange..........any ideas?

  6. #6
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Re: Using VBA to fill col with dates based on start and end date

    ok figured it out. By accident.

    So in my code i pasted values for G2 and G3.

    G3 was actually formatted in a date format of say "9/1/07"

    While the G2 data when it got pasted was in the format of "39295"

    so you had something like this

    39295
    9/1/07

    when you paste this down you get

    39295
    9/1/07
    39296
    9/2/07
    39297
    9/3/07

    which is

    8/1/07
    9/1/07
    8/2/07
    9/2/07
    8/3/07
    9/3/07



    so to fix it i just made sure both the values i put into thte cell were dates like this


    8/1/07
    9/1/07


    when you autofill down this you get the right result.

+ 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