PC Review


Reply
Thread Tools Rate Thread

Compare values in a column

 
 
=?Utf-8?B?VGVuZHJlc3Nl?=
Guest
Posts: n/a
 
      4th Jul 2007
I need help with a macro that checks that cells values in column A are
increasing by one increment. In Column A i put receipts numbers. I want to be
able to check if all receipts have been recorded. for example, if column A
looks like this:

A
1 100
2 101
3 103
4 104
5 105

All values are increasing by 1, except the value in cell A3 increased by 2.
Which means that Receipt Number 102 hasn't been recorded.
I want the macro to go through cells in column A, and once it detects a gap,
the cell fill colour (cell A3 in the above example) turns red.

I'm using Excel 2003.

Many thanks
Tendresse


 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sk1C?=
Guest
Posts: n/a
 
      4th Jul 2007
Perhaps consider conditional formatting. Assuming your data is in A1:A100,
select cells A2:A100, then Format/Conditional Formatting
Formula Is: =a2-a1<>1
then select Format/Pattern-Red. OK out.


"Tendresse" wrote:

> I need help with a macro that checks that cells values in column A are
> increasing by one increment. In Column A i put receipts numbers. I want to be
> able to check if all receipts have been recorded. for example, if column A
> looks like this:
>
> A
> 1 100
> 2 101
> 3 103
> 4 104
> 5 105
>
> All values are increasing by 1, except the value in cell A3 increased by 2.
> Which means that Receipt Number 102 hasn't been recorded.
> I want the macro to go through cells in column A, and once it detects a gap,
> the cell fill colour (cell A3 in the above example) turns red.
>
> I'm using Excel 2003.
>
> Many thanks
> Tendresse
>
>

 
Reply With Quote
 
=?Utf-8?B?Sk1C?=
Guest
Posts: n/a
 
      4th Jul 2007
But if you really need a macro - perhaps this will point you in the right
direction

Sub Test()
Dim rngData As Range
Dim i As Long

Set rngData = Worksheets("Sheet2").Range("A1:A5")

For i = 2 To rngData.Rows.Count
If rngData(i).Value - rngData(i - 1).Value <> 1 Then
rngData.Cells(i).Interior.ColorIndex = 53
Else: rngData.Cells(i).Interior.ColorIndex = xlNone
End If
Next i

End Sub

"Tendresse" wrote:

> I need help with a macro that checks that cells values in column A are
> increasing by one increment. In Column A i put receipts numbers. I want to be
> able to check if all receipts have been recorded. for example, if column A
> looks like this:
>
> A
> 1 100
> 2 101
> 3 103
> 4 104
> 5 105
>
> All values are increasing by 1, except the value in cell A3 increased by 2.
> Which means that Receipt Number 102 hasn't been recorded.
> I want the macro to go through cells in column A, and once it detects a gap,
> the cell fill colour (cell A3 in the above example) turns red.
>
> I'm using Excel 2003.
>
> Many thanks
> Tendresse
>
>

 
Reply With Quote
 
=?Utf-8?B?TWlrZQ==?=
Guest
Posts: n/a
 
      4th Jul 2007
Test on Sheet1
Sub testing()
Const sh1Name = "Sheet1"
Const colA = "A"
Dim sh1 As Worksheet
Dim i As Long
Dim lastRowInColA As Long

Set sh1 = Worksheets(sh1Name)
lastRowInColA = Cells(Rows.Count, colA).End(xlUp).Row

For i = 2 To lastRowInColA
If sh1.Range(colA & i).Offset(1, 0).Value - sh1.Range(colA & i).Value > 1 Then
sh1.Range(colA & i).Offset(1, 0).Interior.ColorIndex = 6

End If
Next i
End Sub

"Tendresse" wrote:

> I need help with a macro that checks that cells values in column A are
> increasing by one increment. In Column A i put receipts numbers. I want to be
> able to check if all receipts have been recorded. for example, if column A
> looks like this:
>
> A
> 1 100
> 2 101
> 3 103
> 4 104
> 5 105
>
> All values are increasing by 1, except the value in cell A3 increased by 2.
> Which means that Receipt Number 102 hasn't been recorded.
> I want the macro to go through cells in column A, and once it detects a gap,
> the cell fill colour (cell A3 in the above example) turns red.
>
> I'm using Excel 2003.
>
> Many thanks
> Tendresse
>
>

 
Reply With Quote
 
=?Utf-8?B?VGVuZHJlc3Nl?=
Guest
Posts: n/a
 
      4th Jul 2007
Hi JMB,
Thanks a lot for your reply. The macro worked perfectly. That's exactly what
i wanted. You are a champion.


"JMB" wrote:

> But if you really need a macro - perhaps this will point you in the right
> direction
>
> Sub Test()
> Dim rngData As Range
> Dim i As Long
>
> Set rngData = Worksheets("Sheet2").Range("A1:A5")
>
> For i = 2 To rngData.Rows.Count
> If rngData(i).Value - rngData(i - 1).Value <> 1 Then
> rngData.Cells(i).Interior.ColorIndex = 53
> Else: rngData.Cells(i).Interior.ColorIndex = xlNone
> End If
> Next i
>
> End Sub
>
> "Tendresse" wrote:
>
> > I need help with a macro that checks that cells values in column A are
> > increasing by one increment. In Column A i put receipts numbers. I want to be
> > able to check if all receipts have been recorded. for example, if column A
> > looks like this:
> >
> > A
> > 1 100
> > 2 101
> > 3 103
> > 4 104
> > 5 105
> >
> > All values are increasing by 1, except the value in cell A3 increased by 2.
> > Which means that Receipt Number 102 hasn't been recorded.
> > I want the macro to go through cells in column A, and once it detects a gap,
> > the cell fill colour (cell A3 in the above example) turns red.
> >
> > I'm using Excel 2003.
> >
> > Many thanks
> > Tendresse
> >
> >

 
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
HELP: Compare Column values with column names in different tables sam Microsoft Access Form Coding 4 26th May 2010 07:56 PM
Look up values in one column and compare with another babypink2807@googlemail.com Microsoft Excel New Users 2 13th Nov 2007 05:47 PM
Compare values in a column =?Utf-8?B?Smlt?= Microsoft Access VBA Modules 11 14th Nov 2006 08:48 PM
HOW TO COMPARE COLUMN VALUES IN EXCEL? =?Utf-8?B?TmV3MkV4Y2Vs?= Microsoft Excel Worksheet Functions 0 28th Sep 2006 07:39 PM
How do I compare string values in one column to another column? =?Utf-8?B?TmljayBOLg==?= Microsoft Excel Worksheet Functions 1 29th Apr 2006 02:56 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:43 PM.