R
RussTheBear
comparing values that don't equal but do equal?
i built a macro that is supposed to check values of one cell versus another
cell
a message is supposed to pop up when the values equal and not when they
don't equal
however, a message pops up regardless of whether they equal or not
there are two conditional areas where the values are tested, which are
called ACTIVE and EDITED
my code is long...the issue is towards the bottom under EDITED, which is the
same as under ACTIVE, but the error only occurs with EDITED
Sub QQQQ()
'---------------------This must stay here-----------------------
'First I have to select Column D to measure the amount of rows
'in order to know when to stop
Range("D10").Select
x = ActiveCell.Row
y = ActiveCell.Column
z = 0
Do While Cells(x, y).Value <> ""
x = x + 1
z = z + 1
Loop
'--------------------------------------------
'--------------------CHECK EDITS--------------
'Calculate the number of rows in the book based of Event Code column
Range("D10").Activate
x = ActiveCell.Row
y = ActiveCell.Column
z = 0
Do While Cells(x, y).Value <> ""
x = x + 1
z = z + 1
Loop
'z is still the height of the book
Range("C10").Select
Selection.End(xlToRight).Select
y = ActiveCell.Column
'make y constant as the last column in the book
y = y + 0
'-----------------------------------
'start checking values in row 11
x = 11
'make w equal the column before the last edit column
w = y - 7
'----------------------------------------------------------------------------------------------------------
'---------------------Check edits for missing confirmation numbers or
missing prices-----------------------
'only performed on active or edited postings
Do
Cells(x, w).Select
If IsError(Cells(x, 1).Value) Then
'then do nothing and go to the next row
x = x + 1
ElseIf Cells(x, 1).Value <> "active" And Cells(x, 1).Value <>
"edited" Then
'then do nothing and go to the next row
x = x + 1
'ACTIVE-----------------------------
ElseIf Cells(x, 1).Value = "active" Then
Do Until w < 29
Cells(x, w).Select
'---------edit columns later than the first edit
'NO EDIT
If Cells(x, w).Value = "" _
And Cells(x, w + 2).Value = "" _
And Cells(x, w + 3).Value = "" _
Then
'EDIT WITH CONFIRMATION NUMBERS
ElseIf Cells(x, w).Value <> "" _
And Cells(x, w + 2).Value <> "" _
And Cells(x, w + 3).Value <> "" _
Then
'MISSING CONFIRMATION NUMBERS
ElseIf Cells(x, w).Value <> "" _
And Cells(x, w + 2).Value = "" _
Or Cells(x, w + 3).Value = "" _
Then
Cells(x, w).Select
MsgBox "Missing confirmation numbers. Record this row
and column and error type, and press OK to coninue the macro."
'don't end sub
'MISSING PRICE
ElseIf Cells(x, w).Value = "" _
And Cells(x, w + 2).Value <> "" _
Or Cells(x, w + 3).Value <> "" _
Then
Cells(x, w).Select
MsgBox "Missing price. Record this row and column and
error type, and press OK to coninue the macro."
'don't end sub
End If
w = w - 4
Loop
x = x + 1
w = y - 7
'EDITED-----------------------------
ElseIf Cells(x, 1).Value = "edited" Then
Do Until w < 29
Cells(x, w).Select
'---------edit columns later than the first edit
'NO EDIT
If Cells(x, w).Value = "" _
And Cells(x, w + 2).Value = "" _
And Cells(x, w + 3).Value = "" _
Then
'EDIT WITH CONFIRMATION NUMBERS
ElseIf Cells(x, w).Value <> "" _
And Cells(x, w + 2).Value <> "" _
And Cells(x, w + 3).Value <> "" _
Then
'MISSING CONFIRMATION NUMBERS
ElseIf Cells(x, w).Value <> "" _
And Cells(x, w + 2).Value = "" _
Or Cells(x, w + 3).Value = "" _
Then
Cells(x, w).Select
MsgBox "Missing confirmation numbers. Record this row
and column and error type, and press OK to coninue the macro."
'don't end sub
'MISSING PRICE
ElseIf Cells(x, w).Value = "" _
And Cells(x, w + 2).Value <> "" _
Or Cells(x, w + 3).Value <> "" _
Then
Cells(x, w).Select
MsgBox "Missing price. Record this row and column and
error type, and press OK to coninue the macro."
'don't end sub
End If
w = w - 4
Loop
x = x + 1
w = y - 7
End If
Loop Until x = z + 10
'----------------------------------------------------------------------------------------------------------
'---------------------Check edits for MATCHING prices-----------------------
'only performed on active or edited postings
'start checking values in row 11
x = 11
'make w equal the last edit column
w = y - 3
'make v equal the next edit column before w
v = w - (4 * a)
'make a a multiple
a = 1
Do
Cells(x, w).Activate
Cells(x, v).Activate
'#N/A-----------------------------
If IsError(Cells(x, 1).Value) Then
Do Until w < 29
Cells(x, w).Select
'ALL BLANK IS GOOD
If Cells(x, w).Value = "" _
And Cells(x, w + 2).Value = "" _
And Cells(x, w + 3).Value = "" _
Then
'ANY VALUES IS BAD
ElseIf Cells(x, w).Value <> "" _
Or Cells(x, w + 2).Value <> "" _
Or Cells(x, w + 3).Value <> "" _
Then
Cells(x, w).Select
MsgBox "This ticket has never been posted. There should
not be any information here. Record this row and column and error type, and
press OK to coninue the macro."
'don't end sub
End If
w = w - 4
Loop
ElseIf Cells(x, 1).Value <> "active" And Cells(x, 1).Value <>
"edited" Then
'then do nothing and go to the next row
'ACTIVE-----------------------------
ElseIf Cells(x, 1).Value = "active" Then
Do Until w = 29 'stop at the second edit column
Cells(x, w).Activate
Cells(x, v).Activate
'NO EDIT FOUND
If Cells(x, w).Value = "" Then
w = w - 4
a = 1
'EDIT FOUND AND NOT EQUAL
ElseIf Cells(x, w).Value <> "" _
And (Cells(x, w).Value <> Cells(x, v).Value) Then
'don't end sub
'but go to the next row by ending the loop by making w =
29
w = 29
'EDIT FOUND AND EQUAL
ElseIf Cells(x, w).Value <> "" _
And (Cells(x, w).Value = Cells(x, v).Value) Then
Cells(x, w).Select
MsgBox "New edit prices cannot match old previous
prices. Record this row and column and error type, and press OK to coninue
the macro."
'don't end sub
'but go to the next row by ending the loop by making w =
29
w = 29
'EDIT FOUND BUT NOT SEQUENTIAL
ElseIf Cells(x, w).Value <> "" _
And Cells(x, v).Value = "" Then
Do
a = a + 1
Loop Until v = 29
End If
Loop
'EDITED-----------------------------
ElseIf Cells(x, 1).Value = "edited" Then
Do Until w = 29 'stop at the second edit column
Cells(x, w).Activate
Cells(x, v).Activate
'NO EDIT FOUND
If Cells(x, w).Value = "" Then
w = w - 4
a = 1
'EDIT FOUND AND NOT EQUAL
ElseIf Cells(x, w).Value <> Cells(x, v).Value Then
'don't end sub
'but go to the next row by ending the loop by making w =
29
w = 29
'***********************************************
'The error occurs below here
'***********************************************
'EDIT FOUND AND EQUAL
ElseIf Cells(x, w).Value = Cells(x, v).Value Then
Cells(x, w).Select
MsgBox "New edit prices cannot match old previous
prices. Record this row and column and error type, and press OK to coninue
the macro."
'don't end sub
'but go to the next row by ending the loop by making w =
29
w = 29
'EDIT FOUND BUT NOT SEQUENTIAL
ElseIf Cells(x, w).Value <> "" _
And Cells(x, v).Value = "" Then
Do
a = a + 1
Loop Until v = 29
End If
Loop
End If
'go to the next row and reset variables
x = x + 1
w = y - 3
v = w - (4 * a)
a = 1
Loop Until x = z + 10
End Sub
i built a macro that is supposed to check values of one cell versus another
cell
a message is supposed to pop up when the values equal and not when they
don't equal
however, a message pops up regardless of whether they equal or not
there are two conditional areas where the values are tested, which are
called ACTIVE and EDITED
my code is long...the issue is towards the bottom under EDITED, which is the
same as under ACTIVE, but the error only occurs with EDITED
Sub QQQQ()
'---------------------This must stay here-----------------------
'First I have to select Column D to measure the amount of rows
'in order to know when to stop
Range("D10").Select
x = ActiveCell.Row
y = ActiveCell.Column
z = 0
Do While Cells(x, y).Value <> ""
x = x + 1
z = z + 1
Loop
'--------------------------------------------
'--------------------CHECK EDITS--------------
'Calculate the number of rows in the book based of Event Code column
Range("D10").Activate
x = ActiveCell.Row
y = ActiveCell.Column
z = 0
Do While Cells(x, y).Value <> ""
x = x + 1
z = z + 1
Loop
'z is still the height of the book
Range("C10").Select
Selection.End(xlToRight).Select
y = ActiveCell.Column
'make y constant as the last column in the book
y = y + 0
'-----------------------------------
'start checking values in row 11
x = 11
'make w equal the column before the last edit column
w = y - 7
'----------------------------------------------------------------------------------------------------------
'---------------------Check edits for missing confirmation numbers or
missing prices-----------------------
'only performed on active or edited postings
Do
Cells(x, w).Select
If IsError(Cells(x, 1).Value) Then
'then do nothing and go to the next row
x = x + 1
ElseIf Cells(x, 1).Value <> "active" And Cells(x, 1).Value <>
"edited" Then
'then do nothing and go to the next row
x = x + 1
'ACTIVE-----------------------------
ElseIf Cells(x, 1).Value = "active" Then
Do Until w < 29
Cells(x, w).Select
'---------edit columns later than the first edit
'NO EDIT
If Cells(x, w).Value = "" _
And Cells(x, w + 2).Value = "" _
And Cells(x, w + 3).Value = "" _
Then
'EDIT WITH CONFIRMATION NUMBERS
ElseIf Cells(x, w).Value <> "" _
And Cells(x, w + 2).Value <> "" _
And Cells(x, w + 3).Value <> "" _
Then
'MISSING CONFIRMATION NUMBERS
ElseIf Cells(x, w).Value <> "" _
And Cells(x, w + 2).Value = "" _
Or Cells(x, w + 3).Value = "" _
Then
Cells(x, w).Select
MsgBox "Missing confirmation numbers. Record this row
and column and error type, and press OK to coninue the macro."
'don't end sub
'MISSING PRICE
ElseIf Cells(x, w).Value = "" _
And Cells(x, w + 2).Value <> "" _
Or Cells(x, w + 3).Value <> "" _
Then
Cells(x, w).Select
MsgBox "Missing price. Record this row and column and
error type, and press OK to coninue the macro."
'don't end sub
End If
w = w - 4
Loop
x = x + 1
w = y - 7
'EDITED-----------------------------
ElseIf Cells(x, 1).Value = "edited" Then
Do Until w < 29
Cells(x, w).Select
'---------edit columns later than the first edit
'NO EDIT
If Cells(x, w).Value = "" _
And Cells(x, w + 2).Value = "" _
And Cells(x, w + 3).Value = "" _
Then
'EDIT WITH CONFIRMATION NUMBERS
ElseIf Cells(x, w).Value <> "" _
And Cells(x, w + 2).Value <> "" _
And Cells(x, w + 3).Value <> "" _
Then
'MISSING CONFIRMATION NUMBERS
ElseIf Cells(x, w).Value <> "" _
And Cells(x, w + 2).Value = "" _
Or Cells(x, w + 3).Value = "" _
Then
Cells(x, w).Select
MsgBox "Missing confirmation numbers. Record this row
and column and error type, and press OK to coninue the macro."
'don't end sub
'MISSING PRICE
ElseIf Cells(x, w).Value = "" _
And Cells(x, w + 2).Value <> "" _
Or Cells(x, w + 3).Value <> "" _
Then
Cells(x, w).Select
MsgBox "Missing price. Record this row and column and
error type, and press OK to coninue the macro."
'don't end sub
End If
w = w - 4
Loop
x = x + 1
w = y - 7
End If
Loop Until x = z + 10
'----------------------------------------------------------------------------------------------------------
'---------------------Check edits for MATCHING prices-----------------------
'only performed on active or edited postings
'start checking values in row 11
x = 11
'make w equal the last edit column
w = y - 3
'make v equal the next edit column before w
v = w - (4 * a)
'make a a multiple
a = 1
Do
Cells(x, w).Activate
Cells(x, v).Activate
'#N/A-----------------------------
If IsError(Cells(x, 1).Value) Then
Do Until w < 29
Cells(x, w).Select
'ALL BLANK IS GOOD
If Cells(x, w).Value = "" _
And Cells(x, w + 2).Value = "" _
And Cells(x, w + 3).Value = "" _
Then
'ANY VALUES IS BAD
ElseIf Cells(x, w).Value <> "" _
Or Cells(x, w + 2).Value <> "" _
Or Cells(x, w + 3).Value <> "" _
Then
Cells(x, w).Select
MsgBox "This ticket has never been posted. There should
not be any information here. Record this row and column and error type, and
press OK to coninue the macro."
'don't end sub
End If
w = w - 4
Loop
ElseIf Cells(x, 1).Value <> "active" And Cells(x, 1).Value <>
"edited" Then
'then do nothing and go to the next row
'ACTIVE-----------------------------
ElseIf Cells(x, 1).Value = "active" Then
Do Until w = 29 'stop at the second edit column
Cells(x, w).Activate
Cells(x, v).Activate
'NO EDIT FOUND
If Cells(x, w).Value = "" Then
w = w - 4
a = 1
'EDIT FOUND AND NOT EQUAL
ElseIf Cells(x, w).Value <> "" _
And (Cells(x, w).Value <> Cells(x, v).Value) Then
'don't end sub
'but go to the next row by ending the loop by making w =
29
w = 29
'EDIT FOUND AND EQUAL
ElseIf Cells(x, w).Value <> "" _
And (Cells(x, w).Value = Cells(x, v).Value) Then
Cells(x, w).Select
MsgBox "New edit prices cannot match old previous
prices. Record this row and column and error type, and press OK to coninue
the macro."
'don't end sub
'but go to the next row by ending the loop by making w =
29
w = 29
'EDIT FOUND BUT NOT SEQUENTIAL
ElseIf Cells(x, w).Value <> "" _
And Cells(x, v).Value = "" Then
Do
a = a + 1
Loop Until v = 29
End If
Loop
'EDITED-----------------------------
ElseIf Cells(x, 1).Value = "edited" Then
Do Until w = 29 'stop at the second edit column
Cells(x, w).Activate
Cells(x, v).Activate
'NO EDIT FOUND
If Cells(x, w).Value = "" Then
w = w - 4
a = 1
'EDIT FOUND AND NOT EQUAL
ElseIf Cells(x, w).Value <> Cells(x, v).Value Then
'don't end sub
'but go to the next row by ending the loop by making w =
29
w = 29
'***********************************************
'The error occurs below here
'***********************************************
'EDIT FOUND AND EQUAL
ElseIf Cells(x, w).Value = Cells(x, v).Value Then
Cells(x, w).Select
MsgBox "New edit prices cannot match old previous
prices. Record this row and column and error type, and press OK to coninue
the macro."
'don't end sub
'but go to the next row by ending the loop by making w =
29
w = 29
'EDIT FOUND BUT NOT SEQUENTIAL
ElseIf Cells(x, w).Value <> "" _
And Cells(x, v).Value = "" Then
Do
a = a + 1
Loop Until v = 29
End If
Loop
End If
'go to the next row and reset variables
x = x + 1
w = y - 3
v = w - (4 * a)
a = 1
Loop Until x = z + 10
End Sub