+ Reply to Thread
Results 1 to 7 of 7

Adding rows for missing dates

  1. #1
    Registered User
    Join Date
    08-29-2013
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    52

    Adding rows for missing dates

    Good morning

    I'm trying to setup a attendance tracker, where I can copy/paste data from our time clock into a Excel worksheet. Have a button with VBA code that will look at a start date in cell D2 and the end date in cell G2, then compare it to data in column K, and add rows with the missing dates, excluding Sundays.

    I have the below code it almost does what I'm looking for but it doesn't allow for my data ranges. I have attached a sample worksheet.

    Can anyone please help with this issue.

    Please Login or Register  to view this content.
    Thanks
    Dave
    Attached Files Attached Files
    Last edited by JBeaucaire; 09-05-2013 at 01:40 PM. Reason: Added CODE tags, as per Forum Rules. Take a moment to read the Forum Rules in the menu bar above. Thanks.

  2. #2
    Valued Forum Contributor
    Join Date
    06-17-2009
    Location
    Chennai,India
    MS-Off Ver
    Excel 2003,excel 2007
    Posts
    678

    Re: Adding rows for missing dates

    I have seen your sheet. logic seems to be confusing. I presume you want the dates to be serially filled for each sub sset of particualr flll name

    for e.g. Jane Doe rows 5 to 9 there is no missisng data
    for Henry Ford the dates between 22nd and 28th (total no. of 5 dates) are missig and you want to insert 5 rows. and fill up the same columns except for the date.

    is this not what you want. This is a complicated task.

    It would have been better if you have designed the data sheet like this

    have one separate sheet for each name and write a common macro for each of the sheets.
    re think on those line and write a macro.
    even now you can copy the data from sheet 1 to each of the name sheet .

    If this suggestion is ok revert back to newsgroup
    I am not an expert. better solutions may be available
    [email protected]

  3. #3
    Forum Contributor
    Join Date
    03-21-2012
    Location
    Ho Chi Minh city
    MS-Off Ver
    Excel 2003
    Posts
    180

    Re: Adding rows for missing dates

    AddRowsForMissingDates.xlsAddRowsForMissingDates.xls
    PHP Code: 
    Option Explicit
    Sub AddRowsForMissingDates
    ()
     
    Dim Cls As RangeRng As RangesRng As Range
     Dim Dat 
    As DateSoNgay As IntegerjJ As Long
         
     Sheet1
    .Select:                                     Dat = [D2].Value
     SoNgay 
    = [g2].Value Dat
     Sheets
    ("GPE").Range("fName").Copy Destination:=[Ba1]
     
    Application.ScreenUpdating False
     
    For Each Cls In [Ba1].CurrentRegion
        
    [ca2].Value Cls.Value
        Range
    ("B5").CurrentRegion.AdvancedFilter Action:=xlFilterCopy_
            CriteriaRange
    :=Range("CA1:CA2"), CopyToRange:=Range("CA4:CK4"), Unique:=False
        Set Rng 
    = [ck5].Resize(35)
        
    Rng.NumberFormat "mm/dd/yyyy"
        
    For jJ 0 To SoNgay
            Set sRng 
    Rng.Find(Format(Dat jJ"mm/dd/yyyy"), , xlValuesxlWhole)
            If 
    sRng Is Nothing Then
                
    If Weekday(Dat jJ) > 1 Then
                    With 
    [A65500].End(xlUp).Offset(1)
                        .
    Resize(, 3) = [Ca5].Resize(, 3).Value
                        Cells
    (.Row"K").Value Dat jJ
                    End With
                End 
    If
            Else
            
    End If
        
    Next jJ
     Next Cls
     Application
    .ScreenUpdating True
     
    [B5].CurrentRegion.Sort Key1:=Range("A5"), Order1:=xlAscendingKey2:=Range("K5"_
        
    Order2:=xlAscendingHeader:=xlGuessOrderCustom:=1MatchCase:= _
        False
    Orientation:=xlTopToBottom
    End Sub 
    Last edited by Sa DQ; 09-06-2013 at 11:38 AM.

  4. #4
    Registered User
    Join Date
    08-29-2013
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: Adding rows for missing dates

    Hi Sa Dq

    This is fantastic it does everything I need good job you rock. I was wondering if you could make two small changes to the code. Right now you have it referencing column A for the first name. Can you have it reference column D because with our export it combines the first and last name in column D. And the only other thing I need is the employee range right now it's pulls 17 employees can you change it to pull 300 employee names? Thanks again for all your help.

  5. #5
    Forum Contributor
    Join Date
    03-21-2012
    Location
    Ho Chi Minh city
    MS-Off Ver
    Excel 2003
    Posts
    180

    Re: Adding rows for missing dates

    /////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\////////////////////////////,,,,,,,,,,,,,,,,,,,,,,,...................
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    08-29-2013
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: [Solved] Adding rows for missing dates

    This is great, you totally solved my issue, job well done.

    Thanks
    Dave

  7. #7
    Registered User
    Join Date
    08-29-2013
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    52

    Re: Adding rows for missing dates

    Hi Guys

    Me again, the above code is working it's currently excluding Sunday's, I need it to exclude Saturdays as well. I just have no idea how to alter the code to make this happen.

    can anyone please help me with this code?

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Adding rows and filling in missing numbers
    By flatlander88 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-14-2013, 01:39 PM
  2. [SOLVED] Adding rows for each missing date
    By kinosh1 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-19-2013, 09:36 PM
  3. Problem with midnight date change using VBA macro for adding missing dates
    By ABoon86 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-11-2012, 10:20 AM
  4. Adding rows of missing dates and times
    By h2005 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-11-2012, 07:21 AM
  5. Adding missing date rows to spreadsheet
    By mikea3 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-11-2008, 09:08 PM

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