Consulting

Results 1 to 5 of 5

Thread: sum data based on dates from sheet to another

  1. #1

    sum data based on dates from sheet to another

    hello
    i try sum data based on cell value contains date so whan i write the date in g2 it supposes sum from the first date to what i write in g2 and copy theses data from a2:e to sheet2 this my code doesn't work also not give me error
    HTML Code:
     Dim l As LongDim LastRow As Long
    Dim oWkSht As Worksheet
    Dim FirstDate As Date
    Dim LastDate As Date
    'Dim tsales As Long  '<-- not used in this code
    
    Set oWkSht = Worksheets("sheet2")
    
    FirstDate = DateSerial(Year(Date), Month(Date), 1)
    LastDate = DateSerial(Year(Date), Month(Date) + 1, 0)
    
    LastRow = oWkSht.Range("A100000").End(xlUp).Row
    
    Sheets("sheet1").Range("g2").Value = Application.WorksheetFunction.SumIfs(oWkSht.Range("e2:e" & LastRow), oWkSht.Range("a2:a" & LastRow), ">=" & CLng(FirstDate), oWkSht.Range("a2:a" & LastRow), "<=" & CLng(LastDate))
    
    End sub
    Attached Files Attached Files

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Try not CLng-ing the Dates in the formula
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    thanks sam but it doesn't show the result in sheet2

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Well, the code says to place the result on sheet1 G2
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  5. #5
    sorry sam about it thank for make attention me

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •