ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   help with code please (https://www.excelbanter.com/excel-programming/328209-help-code-please.html)

Gareth[_3_]

help with code please
 
I have a dates in column J and also dates in column K

What I want to do is check each date in column J to make sure there are no
dates in column K that are within 6 days of it.

That is:
J2=01/04/2005
no date in column K can be <07/04/2005

If there are any then possibly create a list of C2 and the C column values
for the records within 6 days.

Hope this makes sense.

Thanks in advance.

Gareth



Otto Moehrbach

help with code please
 
The following macro does what you want. You said "within 6 days". That
means <=6 days on either side of the Column J date. IOW, the absolute value
of the difference is <=6 days and both dates get copied to Columns C & D.
I am also sending you a small file with this macro placed in the proper
module. I am sending this file to . If this
is not a good address for you and you feel you need further help with this,
please post back. HTH Otto
Sub GetDates()
Dim RngJ As Range
Dim RngK As Range
Dim j As Range
Dim k As Range
Dim Dest As Range
Set Dest = [C2]
Set RngJ = Range("J2", Range("J" & Rows.Count).End(xlUp))
Set RngK = Range("K2", Range("K" & Rows.Count).End(xlUp))
For Each j In RngJ
For Each k In RngK
If Abs(j - k) <= 6 Then
Dest = j
Dest.Offset(, 1) = k
Set Dest = Dest.Offset(1)
End If
Next k
Next j
End Sub
"Gareth" wrote in message
...
I have a dates in column J and also dates in column K

What I want to do is check each date in column J to make sure there are no
dates in column K that are within 6 days of it.

That is:
J2=01/04/2005
no date in column K can be <07/04/2005

If there are any then possibly create a list of C2 and the C column values
for the records within 6 days.

Hope this makes sense.

Thanks in advance.

Gareth





Otto Moehrbach

help with code please
 
Your address is not valid. Otto
"Otto Moehrbach" wrote in message
...
The following macro does what you want. You said "within 6 days". That
means <=6 days on either side of the Column J date. IOW, the absolute
value of the difference is <=6 days and both dates get copied to Columns C
& D.
I am also sending you a small file with this macro placed in the proper
module. I am sending this file to . If this
is not a good address for you and you feel you need further help with
this, please post back. HTH Otto
Sub GetDates()
Dim RngJ As Range
Dim RngK As Range
Dim j As Range
Dim k As Range
Dim Dest As Range
Set Dest = [C2]
Set RngJ = Range("J2", Range("J" & Rows.Count).End(xlUp))
Set RngK = Range("K2", Range("K" & Rows.Count).End(xlUp))
For Each j In RngJ
For Each k In RngK
If Abs(j - k) <= 6 Then
Dest = j
Dest.Offset(, 1) = k
Set Dest = Dest.Offset(1)
End If
Next k
Next j
End Sub
"Gareth" wrote in message
...
I have a dates in column J and also dates in column K

What I want to do is check each date in column J to make sure there are
no
dates in column K that are within 6 days of it.

That is:
J2=01/04/2005
no date in column K can be <07/04/2005

If there are any then possibly create a list of C2 and the C column
values
for the records within 6 days.

Hope this makes sense.

Thanks in advance.

Gareth







Gareth[_3_]

help with code please
 
sorry, deleted that account a few weeks ago.....

please try:



but removing the "not" after family.

"Otto Moehrbach" wrote in message
...
Your address is not valid. Otto
"Otto Moehrbach" wrote in message
...
The following macro does what you want. You said "within 6 days". That
means <=6 days on either side of the Column J date. IOW, the absolute
value of the difference is <=6 days and both dates get copied to Columns

C
& D.
I am also sending you a small file with this macro placed in the proper
module. I am sending this file to
. If
this
is not a good address for you and you feel you need further help with
this, please post back. HTH Otto
Sub GetDates()
Dim RngJ As Range
Dim RngK As Range
Dim j As Range
Dim k As Range
Dim Dest As Range
Set Dest = [C2]
Set RngJ = Range("J2", Range("J" & Rows.Count).End(xlUp))
Set RngK = Range("K2", Range("K" & Rows.Count).End(xlUp))
For Each j In RngJ
For Each k In RngK
If Abs(j - k) <= 6 Then
Dest = j
Dest.Offset(, 1) = k
Set Dest = Dest.Offset(1)
End If
Next k
Next j
End Sub
"Gareth" wrote in message
...
I have a dates in column J and also dates in column K

What I want to do is check each date in column J to make sure there are
no
dates in column K that are within 6 days of it.

That is:
J2=01/04/2005
no date in column K can be <07/04/2005

If there are any then possibly create a list of C2 and the C column
values
for the records within 6 days.

Hope this makes sense.

Thanks in advance.

Gareth










All times are GMT +1. The time now is 01:44 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com