PC Review


Reply
Thread Tools Rate Thread

Comparing two dates in one column

 
 
Koveras
Guest
Posts: n/a
 
      8th Nov 2006
I found this piece of code while searching for a way to underline
anytime there is a date change in column A, but it doesnt always
underline correctly and if ran twice it incorrectly underlines rows.
Where is the bug? I can't find it. Any help is appreciated. thanks!

Dim RowNdx As Long
Dim ColNum As Integer

ColNum = Selection(1).Column
Columns("A:A").Select
Application.ScreenUpdating = False

For RowNdx = Selection(Selection.Cells.Count).Row To _
Selection(1).Row + 1 Step -1
If Cells(RowNdx, ColNum).Value <> Cells(RowNdx - 1, ColNum).Value
Then
Cells(RowNdx - 1, 1).EntireRow.Select
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
End If
Next RowNdx

 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      8th Nov 2006
Try this

Dim RowNdx As Long
Dim ColNum As Long
Dim cell As Range

ColNum = Selection(1).Column
Columns("A:A").Select
Application.ScreenUpdating = False

For RowNdx = Selection(Selection.Cells.Count).Row To _
Selection(1).Row + 1 Step -1
If Cells(RowNdx, ColNum).Value <> Cells(RowNdx - 1, ColNum).Value
Then
With Cells(RowNdx - 1, 1).EntireRow
With .Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
End With
End If
Next RowNdx


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Koveras" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I found this piece of code while searching for a way to underline
> anytime there is a date change in column A, but it doesnt always
> underline correctly and if ran twice it incorrectly underlines rows.
> Where is the bug? I can't find it. Any help is appreciated. thanks!
>
> Dim RowNdx As Long
> Dim ColNum As Integer
>
> ColNum = Selection(1).Column
> Columns("A:A").Select
> Application.ScreenUpdating = False
>
> For RowNdx = Selection(Selection.Cells.Count).Row To _
> Selection(1).Row + 1 Step -1
> If Cells(RowNdx, ColNum).Value <> Cells(RowNdx - 1, ColNum).Value
> Then
> Cells(RowNdx - 1, 1).EntireRow.Select
> With Selection.Borders(xlEdgeBottom)
> .LineStyle = xlContinuous
> .Weight = xlMedium
> .ColorIndex = xlAutomatic
> End With
> End If
> Next RowNdx
>



 
Reply With Quote
 
=?Utf-8?B?SmF5?=
Guest
Posts: n/a
 
      8th Nov 2006
Hi Koveras -

Although the procedure has some unnecessary steps, it seems to work OK when
I test it. Can you describe your symptoms in more detail?
--
Jay


"Koveras" wrote:

> I found this piece of code while searching for a way to underline
> anytime there is a date change in column A, but it doesnt always
> underline correctly and if ran twice it incorrectly underlines rows.
> Where is the bug? I can't find it. Any help is appreciated. thanks!
>
> Dim RowNdx As Long
> Dim ColNum As Integer
>
> ColNum = Selection(1).Column
> Columns("A:A").Select
> Application.ScreenUpdating = False
>
> For RowNdx = Selection(Selection.Cells.Count).Row To _
> Selection(1).Row + 1 Step -1
> If Cells(RowNdx, ColNum).Value <> Cells(RowNdx - 1, ColNum).Value
> Then
> Cells(RowNdx - 1, 1).EntireRow.Select
> With Selection.Borders(xlEdgeBottom)
> .LineStyle = xlContinuous
> .Weight = xlMedium
> .ColorIndex = xlAutomatic
> End With
> End If
> Next RowNdx
>
>

 
Reply With Quote
 
Koveras
Guest
Posts: n/a
 
      8th Nov 2006
It works now. I moved Column("A:A").Select above ColNum =
Selection(1).Column and its no longer underlining randomly. Thanks for
the help.


Jay wrote:
> Hi Koveras -
>
> Although the procedure has some unnecessary steps, it seems to work OK when
> I test it. Can you describe your symptoms in more detail?
> --
> Jay
>
>
> "Koveras" wrote:
>
> > I found this piece of code while searching for a way to underline
> > anytime there is a date change in column A, but it doesnt always
> > underline correctly and if ran twice it incorrectly underlines rows.
> > Where is the bug? I can't find it. Any help is appreciated. thanks!
> >
> > Dim RowNdx As Long
> > Dim ColNum As Integer
> >
> > ColNum = Selection(1).Column
> > Columns("A:A").Select
> > Application.ScreenUpdating = False
> >
> > For RowNdx = Selection(Selection.Cells.Count).Row To _
> > Selection(1).Row + 1 Step -1
> > If Cells(RowNdx, ColNum).Value <> Cells(RowNdx - 1, ColNum).Value
> > Then
> > Cells(RowNdx - 1, 1).EntireRow.Select
> > With Selection.Borders(xlEdgeBottom)
> > .LineStyle = xlContinuous
> > .Weight = xlMedium
> > .ColorIndex = xlAutomatic
> > End With
> > End If
> > Next RowNdx
> >
> >


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Comparing dates Gareth.Evans Microsoft Excel Worksheet Functions 0 26th Mar 2009 08:54 AM
Comparing Dates =?Utf-8?B?ZnViZGFw?= Microsoft Excel Misc 3 27th Sep 2007 03:53 PM
Comparing two dates in one column Koveras Microsoft Excel Misc 1 11th Nov 2006 11:03 PM
Comparing dates Nathan Microsoft VB .NET 3 9th Nov 2004 02:22 AM
Comparing 2 Dates Tim Microsoft Access Form Coding 3 12th Jul 2004 12:35 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:16 AM.