• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

I want to compare data from 2 columns and displaying whether it is approved or not

shal3ni

New Member
I want to make a loop so i can compare the data from both these columns and display whether it is approved or not for my Uerform but rightr now i can only do one row at a time. Please help!! This is my current code:

>>> use code - tags <<<
Code:
Sub Approval()

Dim ws As Worksheet
Set ws = Worksheets("Sheet1")
'calculate if a cell is greater than a specific value
If ws.Range("M3") > ws.Range("S3") Then
ws.Range("V3") = "Not Approved"
Else

ws.Range("V3") = "Approved"
End If
End Sub
 

Attachments

  • BPA Student Loan Form.xlsm
    52 KB · Views: 4
Last edited by a moderator:
Code:
Sub Approval()
Dim LastRow As Long
Dim i As Long

LastRow = Cells(Rows.Count, "M").End(xlUp).Row


For i = LastRow To 1 Step -1

   If Range("M" & i).Value > Range("S" & i).Value Then
        Range("V" & i).Value = "Not Approved"
    Else
        Range("V" & i).Value = "Approved"
   End If
Next i

End Sub
 
Is there a way to add a msg box saying if the form is approved or not? , i tried but its in a loop so 5 msg boxes appear all at once when i tried adding it.
 
This might be a better approach as it first checks to verify the Col V cell in the specific row is empty. That way it will only
process a new entry and not show multiple MsgBox's when they are not warranted.

Code:
Sub Approval()
Dim LastRow As Long
Dim i As Long

LastRow = Cells(Rows.Count, "M").End(xlUp).Row


For i = LastRow To 1 Step -1
    If Range("V" & i).Value = "" Then
        If Range("M" & i).Value > Range("S" & i).Value Then
            Range("V" & i).Value = "Not Approved"
            Exit Sub
        Else
            If Range("V" & i).Value = "" Then
                Range("V" & i).Value = "Approved"
            End If
            MsgBox "Approved"
            Exit Sub
        End If
    End If
Next i

End Sub
 
Back
Top