VBA to verify data in multiple columns

Godwin117

Board Regular
Joined
Dec 19, 2019
Messages
68
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
I have this VBA, it checks to ensure the correct info is put into the cell, it uses column "E", based on that input, verifies that the correct information was put into column "H" The issue I'm running into is it either doesn't recognize the column is blank or it doesn't go per row when it is verifying. The VBA is below.

Sub Verify_Data()
Application.ScreenUpdating = False
On Error Resume Next

Dim iAE As Variant, iAH As Variant, iR&, lR&

dtext = "PDY"
lR = Cells(Rows.Count, 1).End(xlUp).Row
iAE = Range("E12:E" & lR).Value
iAH = Range("H12:H" & lR).Value
For iR = 1 To UBound(iAE)
If iAE(iR, 1) = dtext Then
If iAH(iR, 1) <> "BMM" Or "DEP" Or "FTX" Or "QUARTERS" Or "RECOVERY" Or "" Then
mt = "Status Error"
mp = "Need to check Date in H" & iR& + 11
m = MsgBox(mp, vbOKOnly, mt)
Exit Sub
End If

End If

Next
End Sub
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Hi,
try this update to your code & see if does what you want

VBA Code:
Sub Verify_Data()
    Dim iAE As Variant, iAH As Variant, m As Variant
    Dim iR As Long, lR As Long
    Dim mp As String
    
    dtext = "PDY"
    
    lR = Cells(Rows.Count, 5).End(xlUp).Row
    iAE = Range("E12:E" & lR).Value
    iAH = Range("H12:H" & lR).Value
    
    For iR = 1 To UBound(iAE)
        If iAE(iR, 1) = dtext Then
            m = Application.Match(iAH(iR, 1), Array("BMM", "DEP", "FTX", "QUARTERS", "RECOVERY"), 0)
            If IsError(m) Then
                mp = "Need to check Date in H" & iR + 11
                MsgBox mp, vbOKOnly, "Status Error"
            Exit Sub
        End If
            End If
    Next iR
End Sub

Dave
 
Upvote 0
Hi,
try this update to your code & see if does what you want

VBA Code:
Sub Verify_Data()
    Dim iAE As Variant, iAH As Variant, m As Variant
    Dim iR As Long, lR As Long
    Dim mp As String
   
    dtext = "PDY"
   
    lR = Cells(Rows.Count, 5).End(xlUp).Row
    iAE = Range("E12:E" & lR).Value
    iAH = Range("H12:H" & lR).Value
   
    For iR = 1 To UBound(iAE)
        If iAE(iR, 1) = dtext Then
            m = Application.Match(iAH(iR, 1), Array("BMM", "DEP", "FTX", "QUARTERS", "RECOVERY"), 0)
            If IsError(m) Then
                mp = "Need to check Date in H" & iR + 11
                MsgBox mp, vbOKOnly, "Status Error"
            Exit Sub
        End If
            End If
    Next iR
End Sub

Dave
Thank you for your response, I tried the code and it doesnt skip the blanks, not sure if that's an option.
 
Upvote 0
Thank you for your response, I tried the code and it doesnt skip the blanks, not sure if that's an option.

I overlooked that

try

VBA Code:
Sub Verify_Data()
    Dim iAE As Variant, iAH As Variant, m As Variant
    Dim iR As Long, lR As Long
    Dim mp As String
    
    dtext = "PDY"
    
    lR = Cells(Rows.Count, 5).End(xlUp).Row
    iAE = Range("E12:E" & lR).Value
    iAH = Range("H12:H" & lR).Value
    
    For iR = 1 To UBound(iAE)
        If iAE(iR, 1) = dtext And Len(iAH(iR, 1)) > 0 Then
            m = Application.Match(iAH(iR, 1), Array("BMM", "DEP", "FTX", "QUARTERS", "RECOVERY"), 0)
            If IsError(m) Then
                mp = "Need to check Date in H" & iR + 11
                MsgBox mp, vbOKOnly, "Status Error"
            Exit Sub
        End If
            End If
    Next iR
End Sub

Dave
 
Upvote 0

Forum statistics

Threads
1,223,239
Messages
6,170,947
Members
452,368
Latest member
jayp2104

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top