|
-
Jul 12th, 2005, 02:55 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Comparing values in one column
Hi!
I really need some help to this!
I have a column in which I want to compare values. First the cell B2 need comparison with other cells and if there is a match - it colors both cells red.
Then it's B3's turn for comparison and so on. This is what I've got so far:
Sub Drwcheck()
Dim iCompare As Long
Dim iCheck As Long
Dim XL As Variant
Dim xlWS As Variant
Dim Checksum As Integer
Dim Compare As Integer
Dim Chk As Integer
Set xlWS = ActiveSheet
Dim colXLparams As New Collection
iCompare = 3
iCheck = 2
Chk = 0
Do While xlWS.Cells(iCompare, 2).Value <> ""
Checksum = Cells(iCheck, 2)
Compare = Cells(iCompare, 2)
If Checksum = Compare Then GoTo Paint Else
iCompare = iCompare + 1
Loop
Paint:
MsgBox "Fejl!!", vbCritical
With Cells(iCheck, 2).Interior
.Color = RGB(255, 0, 0)
End With
With Cells(iCompare, 2).Interior
.Color = RGB(255, 0, 0)
End With
End Sub
But it only compares the first cell :s
Help me, please
-
Jul 12th, 2005, 06:42 AM
#2
Member
Re: Comparing values in one column
Sveegard,
I'm pretty new to programming, but I think I see part of your problem.
Your code goes straight through and hits this line:
VB Code:
Do While xlWS.Cells(iCompare, 2).Value <> ""
Checksum = Cells(iCheck, 2)
Compare = Cells(iCompare, 2)
If Checksum = Compare Then GoTo Paint Else
If your condition is met, it jumps to here:
VB Code:
Paint:
MsgBox "Fejl!!", vbCritical
With Cells(iCheck, 2).Interior
.Color = RGB(255, 0, 0)
End With
With Cells(iCompare, 2).Interior
.Color = RGB(255, 0, 0)
End With
End Sub
And you have it exit the sub.
So it never gets to here:
VB Code:
iCompare = iCompare + 1
Loop
It looks like your code will run until it finds one value to paint, and then quit.
Try:
VB Code:
Sub Drwcheck()
Dim iCompare As Long
Dim iCheck As Long
Dim XL As Variant
Dim xlWS As Variant
Dim Checksum As Integer
Dim Compare As Integer
Dim Chk As Integer
Set xlWS = ActiveSheet
Dim colXLparams As New Collection
iCompare = 3
iCheck = 2
Chk = 0
Do While xlWS.Cells(iCompare, 2).Value <> ""
Checksum = Cells(iCheck, 2)
Compare = Cells(iCompare, 2)
If Checksum = Compare Then
MsgBox "Fejl!!", vbCritical
With Cells(iCheck, 2).Interior
.Color = RGB(255, 0, 0)
End With
With Cells(iCompare, 2).Interior
.Color = RGB(255, 0, 0)
End With
iCompare = iCompare + 1
Else
iCompare = iCompare + 1
Loop
End Sub
Maybe that will work... good luck!
-
Jul 12th, 2005, 08:50 AM
#3
Thread Starter
Addicted Member
Re: Comparing values in one column
Thanks!
I'll try your suggestion, I'll post yet a thread if it doesn't work.
-
Jul 13th, 2005, 01:56 AM
#4
Thread Starter
Addicted Member
Re: Comparing values in one column
Nope, it doesn't work.
It says: "Loop without do"!
Typical for MS programs - nothing works :s
-
Jul 13th, 2005, 05:35 AM
#5
Junior Member
Re: Comparing values in one column
Try throwing an End If in there right before the Loop command. It looks to me like it's considering your Loop command to be part of the preceding Else statement.
-
Jul 13th, 2005, 07:03 AM
#6
Member
Re: Comparing values in one column
Yeah, I'm sorry Sveegaard, what Mike said. I left out the End If there. Hope that works for you.
-
Jul 13th, 2005, 07:27 AM
#7
Thread Starter
Addicted Member
Re: Comparing values in one column
Yeah but thanks for you help anyway. Just need a little thing more (see my other thread)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|