Click here to Skip to main content
15,881,027 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want solution for following scenario can anyone help me.?

want to get date difference in days from two dates using macro in excel. addition on that first date should be from sheet1 and another(2nd) date is from sheet2 and their output(days difference) we have to show in sheet3 in excel.
Posted

Try
VB
Dim sh1 As Worksheet
Dim sh2 As Worksheet

Set sh1 = ActiveWorkbook.Sheets('Sheet 1')
Set sh2 = ActiveWorkbook.Sheets('Sheet 1')

DateDiff("q",sh1.Range("B1") , sh2.Range("B1"))
 
Share this answer
 
Comments
Member 11553122 17-Apr-15 3:58am    
Its not working. giving compile error and syntax error.
Abhinav S 17-Apr-15 5:52am    
That's the general idea. You will have to write your own code!
Member 11553122 21-Apr-15 3:12am    
I want to use macro for that. tahnks fro your idea but its not that much usefull for me...
Can you suggest me something else.?
Private Sub CommandButton1_Click()
Dim currDate As Date
Dim dateOffset As Integer
Dim count1 As Integer
Dim str As String
Dim c***final As Integer
Dim strfinal As String
countfinal = 2
count1 = 2
count0 = 2
strdate = "d" & CStr(count0)

For Each cell In Range(Sheet3.Range(strdate), Sheet3.Range(strdate).End(xlDown))
strdate = "d" & CStr(count0)
count0 = count0 + 1
If cell Is Nothing Then GoTo line10
startDate = Sheets("Sheet3").Range(strdate)
str = "h" & CStr(count1)
For Each cell1 In Range(Sheet3.Range(str), Sheet3.Range(str).End(xlDown))
count1 = count1 + 1
GoTo line20
Next cell1
line20:
If cell1 Is Nothing Then GoTo line10
currDate = Sheets("Sheet3").Range(str)
If currDate = "12:00:00 AM" Then GoTo line40
dateOffset = DateDiff("d", startDate, currDate)
line30:
strfinal = "j" & CStr(countfinal)
Sheets("Sheet3").Range(strfinal) = dateOffset
countfinal = countfinal + 1
line10:
Next cell

line40:
strfinal = "j" & CStr(countfinal)
Sheets("Sheet3").Range(strfinal) = " "
countfinal = countfinal + 1
GoTo line10
End Sub
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900