Why IsDate doesn't work as expected ? and how do I get date value of the next cell in a column? [duplicate]IsDate function returns unexpected resultsCopy a Row of Data based on a conditional 'Date' value from sheet2 to sheet1Excel: Move selection to next blank row in specific column, and enumerate selection by date and typeVBA copy and paste multiple cells, without overwriting existing informationHow to put dates from a for next loop in cells of excelHide Selected Columns in Excel using (VBA) Click ButtonVBA - calculate and print answer for many rowsHow to import the entire row(s) containing current (today's) date from a excel file into another excel file automatically without opening with VBAIs it possible to define a range in VBA based on a value given in a cell? And get sum at end of the range in each column at each timeExcel VBA macro to send emails to unique users in rangeLoop through range and if cell contains value copy to next empty cell in column
Iterate over non-const variables in C++
Why are all my history books dividing Chinese history after the Han dynasty?
When going by a train from Paris to Düsseldorf (Thalys), can I hop off in Köln and then hop on again?
Singapore to Sydney to Canberra: where do we clear customs
A planet illuminated by a black hole?
Is it legal to use cash pulled from a credit card to pay the monthly payment on that credit card?
What to do when you reach a conclusion and find out later on that someone else already did?
Commercial jet accompanied by small plane near Seattle
TSA asking to see cell phone
How can I prevent corporations from growing their own workforce?
An inequality that eludes me.
This message is flooding my syslog, how to find where it comes from?
What self-defense weapons are legal in London?
Giant alien flies into the solar system; the rocky planets are its eggs
Why are so many countries still in the Commonwealth?
Integral of the integral using NIntegrate
Expansion with *.txt in the shell doesn't work if no .txt file exists
"Hello World" as 'prove.web' program source code in Knuth's WEB to test a WEB's pascal to javascript compiler
Explain why watch 'jobs' does not work but watch 'ps' work?
How to deal with a player who makes bad characters and kills them?
How do I run a game when my PCs have different approaches to combat?
Drillers for petroleum strike gusher of blood
How can I receive packages while in France?
What does "see" in "the Holy See" mean?
Why IsDate doesn't work as expected ? and how do I get date value of the next cell in a column? [duplicate]
IsDate function returns unexpected resultsCopy a Row of Data based on a conditional 'Date' value from sheet2 to sheet1Excel: Move selection to next blank row in specific column, and enumerate selection by date and typeVBA copy and paste multiple cells, without overwriting existing informationHow to put dates from a for next loop in cells of excelHide Selected Columns in Excel using (VBA) Click ButtonVBA - calculate and print answer for many rowsHow to import the entire row(s) containing current (today's) date from a excel file into another excel file automatically without opening with VBAIs it possible to define a range in VBA based on a value given in a cell? And get sum at end of the range in each column at each timeExcel VBA macro to send emails to unique users in rangeLoop through range and if cell contains value copy to next empty cell in column
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
This question already has an answer here:
IsDate function returns unexpected results
2 answers
I am currently working on a sheet, specifically column that contains various data types; where I am interested in calculating difference between the first date occured in the column and the next one to it (because the main problem is that the data in the column is heterogeneous and I am interested just in succession ).
So for each cell in the range I have to check whether is a Date , and if so calculate difference between the actual date and the that of the next cell.
I have tried some code but all I can say it is not stable since the IsDate function is acting wierd and seems to change the outcome for different reasons but never the same.
Sub loopDate()
Dim rnge, cell As range
Set rnge = range("P1:P21")
Application.ScreenUpdating = True
For Each cell In rnge
cd = cell.Value2
If IsDate(cd) = True Then
If IsDate(ActiveCell.Offset(1, 0)) = True Then
n = DateDiff("d", cd, ActiveCell.Offset(1, 0))
If n < 0 Then
MsgBox "here is a difference " & n
Else
MsgBox "normal pos diff " & n
End If
Else
MsgBox "contenent of the this cell isnt date intIF "
End If
Else
MsgBox "contenent of the this cell isnt date outIF "
End If
Next
End Sub
I am expecting either a negative or positive number that will refer to difference between two dates and tell weather we still gave time or we already got the deadline passed.
thanks for any help or suggestions about the code above.
excel vba
marked as duplicate by Storax, Vityata
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 26 at 19:30
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
add a comment |
This question already has an answer here:
IsDate function returns unexpected results
2 answers
I am currently working on a sheet, specifically column that contains various data types; where I am interested in calculating difference between the first date occured in the column and the next one to it (because the main problem is that the data in the column is heterogeneous and I am interested just in succession ).
So for each cell in the range I have to check whether is a Date , and if so calculate difference between the actual date and the that of the next cell.
I have tried some code but all I can say it is not stable since the IsDate function is acting wierd and seems to change the outcome for different reasons but never the same.
Sub loopDate()
Dim rnge, cell As range
Set rnge = range("P1:P21")
Application.ScreenUpdating = True
For Each cell In rnge
cd = cell.Value2
If IsDate(cd) = True Then
If IsDate(ActiveCell.Offset(1, 0)) = True Then
n = DateDiff("d", cd, ActiveCell.Offset(1, 0))
If n < 0 Then
MsgBox "here is a difference " & n
Else
MsgBox "normal pos diff " & n
End If
Else
MsgBox "contenent of the this cell isnt date intIF "
End If
Else
MsgBox "contenent of the this cell isnt date outIF "
End If
Next
End Sub
I am expecting either a negative or positive number that will refer to difference between two dates and tell weather we still gave time or we already got the deadline passed.
thanks for any help or suggestions about the code above.
excel vba
marked as duplicate by Storax, Vityata
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 26 at 19:30
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
I believe.Value2ignores the Date so you should use.Valueinstead.
– Damian
Mar 26 at 17:36
I corrected the code formatting. There is an End If missing close to the end
– Sam
Mar 26 at 17:37
The cell you're targeting must have Date as the format (Ctrl-1)
– user2261597
Mar 26 at 17:41
1
Are you sure you want to access the ActiveCell in this lineIf IsDate(ActiveCell.Offset(1, 0)) = True Then. But what you get worng is thatIsDate(cd)will always give false in case the cell contains a date as cd is double.
– Storax
Mar 26 at 17:45
add a comment |
This question already has an answer here:
IsDate function returns unexpected results
2 answers
I am currently working on a sheet, specifically column that contains various data types; where I am interested in calculating difference between the first date occured in the column and the next one to it (because the main problem is that the data in the column is heterogeneous and I am interested just in succession ).
So for each cell in the range I have to check whether is a Date , and if so calculate difference between the actual date and the that of the next cell.
I have tried some code but all I can say it is not stable since the IsDate function is acting wierd and seems to change the outcome for different reasons but never the same.
Sub loopDate()
Dim rnge, cell As range
Set rnge = range("P1:P21")
Application.ScreenUpdating = True
For Each cell In rnge
cd = cell.Value2
If IsDate(cd) = True Then
If IsDate(ActiveCell.Offset(1, 0)) = True Then
n = DateDiff("d", cd, ActiveCell.Offset(1, 0))
If n < 0 Then
MsgBox "here is a difference " & n
Else
MsgBox "normal pos diff " & n
End If
Else
MsgBox "contenent of the this cell isnt date intIF "
End If
Else
MsgBox "contenent of the this cell isnt date outIF "
End If
Next
End Sub
I am expecting either a negative or positive number that will refer to difference between two dates and tell weather we still gave time or we already got the deadline passed.
thanks for any help or suggestions about the code above.
excel vba
This question already has an answer here:
IsDate function returns unexpected results
2 answers
I am currently working on a sheet, specifically column that contains various data types; where I am interested in calculating difference between the first date occured in the column and the next one to it (because the main problem is that the data in the column is heterogeneous and I am interested just in succession ).
So for each cell in the range I have to check whether is a Date , and if so calculate difference between the actual date and the that of the next cell.
I have tried some code but all I can say it is not stable since the IsDate function is acting wierd and seems to change the outcome for different reasons but never the same.
Sub loopDate()
Dim rnge, cell As range
Set rnge = range("P1:P21")
Application.ScreenUpdating = True
For Each cell In rnge
cd = cell.Value2
If IsDate(cd) = True Then
If IsDate(ActiveCell.Offset(1, 0)) = True Then
n = DateDiff("d", cd, ActiveCell.Offset(1, 0))
If n < 0 Then
MsgBox "here is a difference " & n
Else
MsgBox "normal pos diff " & n
End If
Else
MsgBox "contenent of the this cell isnt date intIF "
End If
Else
MsgBox "contenent of the this cell isnt date outIF "
End If
Next
End Sub
I am expecting either a negative or positive number that will refer to difference between two dates and tell weather we still gave time or we already got the deadline passed.
thanks for any help or suggestions about the code above.
This question already has an answer here:
IsDate function returns unexpected results
2 answers
excel vba
excel vba
edited Mar 27 at 7:47
Pᴇʜ
30.2k6 gold badges30 silver badges56 bronze badges
30.2k6 gold badges30 silver badges56 bronze badges
asked Mar 26 at 17:32
I.MAELI.MAEL
1
1
marked as duplicate by Storax, Vityata
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 26 at 19:30
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
marked as duplicate by Storax, Vityata
StackExchange.ready(function()
if (StackExchange.options.isMobile) return;
$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');
$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();
);
);
);
Mar 26 at 19:30
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
I believe.Value2ignores the Date so you should use.Valueinstead.
– Damian
Mar 26 at 17:36
I corrected the code formatting. There is an End If missing close to the end
– Sam
Mar 26 at 17:37
The cell you're targeting must have Date as the format (Ctrl-1)
– user2261597
Mar 26 at 17:41
1
Are you sure you want to access the ActiveCell in this lineIf IsDate(ActiveCell.Offset(1, 0)) = True Then. But what you get worng is thatIsDate(cd)will always give false in case the cell contains a date as cd is double.
– Storax
Mar 26 at 17:45
add a comment |
I believe.Value2ignores the Date so you should use.Valueinstead.
– Damian
Mar 26 at 17:36
I corrected the code formatting. There is an End If missing close to the end
– Sam
Mar 26 at 17:37
The cell you're targeting must have Date as the format (Ctrl-1)
– user2261597
Mar 26 at 17:41
1
Are you sure you want to access the ActiveCell in this lineIf IsDate(ActiveCell.Offset(1, 0)) = True Then. But what you get worng is thatIsDate(cd)will always give false in case the cell contains a date as cd is double.
– Storax
Mar 26 at 17:45
I believe
.Value2 ignores the Date so you should use .Value instead.– Damian
Mar 26 at 17:36
I believe
.Value2 ignores the Date so you should use .Value instead.– Damian
Mar 26 at 17:36
I corrected the code formatting. There is an End If missing close to the end
– Sam
Mar 26 at 17:37
I corrected the code formatting. There is an End If missing close to the end
– Sam
Mar 26 at 17:37
The cell you're targeting must have Date as the format (Ctrl-1)
– user2261597
Mar 26 at 17:41
The cell you're targeting must have Date as the format (Ctrl-1)
– user2261597
Mar 26 at 17:41
1
1
Are you sure you want to access the ActiveCell in this line
If IsDate(ActiveCell.Offset(1, 0)) = True Then. But what you get worng is that IsDate(cd) will always give false in case the cell contains a date as cd is double.– Storax
Mar 26 at 17:45
Are you sure you want to access the ActiveCell in this line
If IsDate(ActiveCell.Offset(1, 0)) = True Then. But what you get worng is that IsDate(cd) will always give false in case the cell contains a date as cd is double.– Storax
Mar 26 at 17:45
add a comment |
2 Answers
2
active
oldest
votes
try this:
Sub loopDate()
Dim rnge, cell As Range
Set rnge = Range("P1:P21")
For Each cell In rnge
If IsDate(cell) = True Then
If IsDate(cell.Offset(1, 0)) = True Then
n = DateDiff("d", cell, cell.Offset(1, 0))
If n < 0 Then
MsgBox "here is a difference " & n
Else
MsgBox "normal pos diff " & n
End If
Else
MsgBox "contenent of the this cell isnt date intIF "
End If
Else
MsgBox "contenent of the this cell isnt date outIF "
End If
Next
End Sub
add a comment |
If I understand you correctly, this is what you're trying to achieve; I have cleaned up some of the unnecessary bits and now you just have to edit DateCol and FindLastRow as is necessary.
Sub loopDate()
'Dim rnge As Range, cell As Range
Dim DateCol As Integer, FindLastRow As Single Dim i As Single
'Set rnge = Range("P1:P21")
'Application.ScreenUpdating = True
' For Each cell In rnge
DateCol = 16
FindLastRow = 21
For i = 1 To FindLastRow
' cd = cell.Value2
If IsDate(Cells(i, DateCol)) Then
If IsDate(Cells(i, DateCol + 1)) Then
n = DateDiff("d", Cells(i, DateCol).Value, Cells(i, DateCol + 1).Value)
If n < 0 Then
MsgBox "here is a difference " & n
Else
MsgBox "normal pos diff " & n
End If
Else
MsgBox "contenent of the this cell isnt date intIF "
End If
Else
MsgBox "contenent of the this cell isnt date outIF "
End If
' Next
Next i
End Sub
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
try this:
Sub loopDate()
Dim rnge, cell As Range
Set rnge = Range("P1:P21")
For Each cell In rnge
If IsDate(cell) = True Then
If IsDate(cell.Offset(1, 0)) = True Then
n = DateDiff("d", cell, cell.Offset(1, 0))
If n < 0 Then
MsgBox "here is a difference " & n
Else
MsgBox "normal pos diff " & n
End If
Else
MsgBox "contenent of the this cell isnt date intIF "
End If
Else
MsgBox "contenent of the this cell isnt date outIF "
End If
Next
End Sub
add a comment |
try this:
Sub loopDate()
Dim rnge, cell As Range
Set rnge = Range("P1:P21")
For Each cell In rnge
If IsDate(cell) = True Then
If IsDate(cell.Offset(1, 0)) = True Then
n = DateDiff("d", cell, cell.Offset(1, 0))
If n < 0 Then
MsgBox "here is a difference " & n
Else
MsgBox "normal pos diff " & n
End If
Else
MsgBox "contenent of the this cell isnt date intIF "
End If
Else
MsgBox "contenent of the this cell isnt date outIF "
End If
Next
End Sub
add a comment |
try this:
Sub loopDate()
Dim rnge, cell As Range
Set rnge = Range("P1:P21")
For Each cell In rnge
If IsDate(cell) = True Then
If IsDate(cell.Offset(1, 0)) = True Then
n = DateDiff("d", cell, cell.Offset(1, 0))
If n < 0 Then
MsgBox "here is a difference " & n
Else
MsgBox "normal pos diff " & n
End If
Else
MsgBox "contenent of the this cell isnt date intIF "
End If
Else
MsgBox "contenent of the this cell isnt date outIF "
End If
Next
End Sub
try this:
Sub loopDate()
Dim rnge, cell As Range
Set rnge = Range("P1:P21")
For Each cell In rnge
If IsDate(cell) = True Then
If IsDate(cell.Offset(1, 0)) = True Then
n = DateDiff("d", cell, cell.Offset(1, 0))
If n < 0 Then
MsgBox "here is a difference " & n
Else
MsgBox "normal pos diff " & n
End If
Else
MsgBox "contenent of the this cell isnt date intIF "
End If
Else
MsgBox "contenent of the this cell isnt date outIF "
End If
Next
End Sub
answered Mar 26 at 17:50
W-hitW-hit
1888 bronze badges
1888 bronze badges
add a comment |
add a comment |
If I understand you correctly, this is what you're trying to achieve; I have cleaned up some of the unnecessary bits and now you just have to edit DateCol and FindLastRow as is necessary.
Sub loopDate()
'Dim rnge As Range, cell As Range
Dim DateCol As Integer, FindLastRow As Single Dim i As Single
'Set rnge = Range("P1:P21")
'Application.ScreenUpdating = True
' For Each cell In rnge
DateCol = 16
FindLastRow = 21
For i = 1 To FindLastRow
' cd = cell.Value2
If IsDate(Cells(i, DateCol)) Then
If IsDate(Cells(i, DateCol + 1)) Then
n = DateDiff("d", Cells(i, DateCol).Value, Cells(i, DateCol + 1).Value)
If n < 0 Then
MsgBox "here is a difference " & n
Else
MsgBox "normal pos diff " & n
End If
Else
MsgBox "contenent of the this cell isnt date intIF "
End If
Else
MsgBox "contenent of the this cell isnt date outIF "
End If
' Next
Next i
End Sub
add a comment |
If I understand you correctly, this is what you're trying to achieve; I have cleaned up some of the unnecessary bits and now you just have to edit DateCol and FindLastRow as is necessary.
Sub loopDate()
'Dim rnge As Range, cell As Range
Dim DateCol As Integer, FindLastRow As Single Dim i As Single
'Set rnge = Range("P1:P21")
'Application.ScreenUpdating = True
' For Each cell In rnge
DateCol = 16
FindLastRow = 21
For i = 1 To FindLastRow
' cd = cell.Value2
If IsDate(Cells(i, DateCol)) Then
If IsDate(Cells(i, DateCol + 1)) Then
n = DateDiff("d", Cells(i, DateCol).Value, Cells(i, DateCol + 1).Value)
If n < 0 Then
MsgBox "here is a difference " & n
Else
MsgBox "normal pos diff " & n
End If
Else
MsgBox "contenent of the this cell isnt date intIF "
End If
Else
MsgBox "contenent of the this cell isnt date outIF "
End If
' Next
Next i
End Sub
add a comment |
If I understand you correctly, this is what you're trying to achieve; I have cleaned up some of the unnecessary bits and now you just have to edit DateCol and FindLastRow as is necessary.
Sub loopDate()
'Dim rnge As Range, cell As Range
Dim DateCol As Integer, FindLastRow As Single Dim i As Single
'Set rnge = Range("P1:P21")
'Application.ScreenUpdating = True
' For Each cell In rnge
DateCol = 16
FindLastRow = 21
For i = 1 To FindLastRow
' cd = cell.Value2
If IsDate(Cells(i, DateCol)) Then
If IsDate(Cells(i, DateCol + 1)) Then
n = DateDiff("d", Cells(i, DateCol).Value, Cells(i, DateCol + 1).Value)
If n < 0 Then
MsgBox "here is a difference " & n
Else
MsgBox "normal pos diff " & n
End If
Else
MsgBox "contenent of the this cell isnt date intIF "
End If
Else
MsgBox "contenent of the this cell isnt date outIF "
End If
' Next
Next i
End Sub
If I understand you correctly, this is what you're trying to achieve; I have cleaned up some of the unnecessary bits and now you just have to edit DateCol and FindLastRow as is necessary.
Sub loopDate()
'Dim rnge As Range, cell As Range
Dim DateCol As Integer, FindLastRow As Single Dim i As Single
'Set rnge = Range("P1:P21")
'Application.ScreenUpdating = True
' For Each cell In rnge
DateCol = 16
FindLastRow = 21
For i = 1 To FindLastRow
' cd = cell.Value2
If IsDate(Cells(i, DateCol)) Then
If IsDate(Cells(i, DateCol + 1)) Then
n = DateDiff("d", Cells(i, DateCol).Value, Cells(i, DateCol + 1).Value)
If n < 0 Then
MsgBox "here is a difference " & n
Else
MsgBox "normal pos diff " & n
End If
Else
MsgBox "contenent of the this cell isnt date intIF "
End If
Else
MsgBox "contenent of the this cell isnt date outIF "
End If
' Next
Next i
End Sub
answered Mar 26 at 18:18
user11262103user11262103
16
16
add a comment |
add a comment |
I believe
.Value2ignores the Date so you should use.Valueinstead.– Damian
Mar 26 at 17:36
I corrected the code formatting. There is an End If missing close to the end
– Sam
Mar 26 at 17:37
The cell you're targeting must have Date as the format (Ctrl-1)
– user2261597
Mar 26 at 17:41
1
Are you sure you want to access the ActiveCell in this line
If IsDate(ActiveCell.Offset(1, 0)) = True Then. But what you get worng is thatIsDate(cd)will always give false in case the cell contains a date as cd is double.– Storax
Mar 26 at 17:45