VBA to create an error log based on IF AND statement

bbalch

Board Regular
Joined
Feb 23, 2015
Messages
61
Hello. I'm hoping you all can help me create a macro that will loop through multiple sheets to identify errors and log those on an ErrorLog worksheet. The excel file is a system generated report with 115 tabs. Column A = Descriptions and Column B = Values. If Column A is blank " " (there are four spaces and that is it) and Column B has a value, then that row exported in error and needs to be addressed.

I would like for the macro to identify rows where Column A is blank " " and Column B isNumeric and log that Tab Name and Row Number on the Errorlog worksheet.

Any suggestions on how to modify the code below to create the IF And statement that is needed on how to create an output log for the values that are errors?

Thanks in advance for your help.

Code:
Sub FindErrors()

    Dim cell    As Range
    Dim LastRow As Long
    Dim rng     As Range
    Dim wks     As Worksheet
    
    
    Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = "ErrorLog"
    
    For Each Sh In Worksheets
    Sh.Activate
    
        Set wks = ActiveSheet
    
        Set rng = wks.Range("A10")
        LastRow = wks.Cells(Rows.Count, rng.Column).End(xlUp).Row
        Set rng = rng.Resize(LastRow - rng.Row + 1, 1)
        
        With Application
            .ScreenUpdating = False
            .Calculation = xlCalculationManual
            
            For Each cell In rng
              ' to test for blanks in column A, and if B is a value
                If Left(cell, 4) = "    " And IsNumeric(##I'm not sure what to put here?) Then
                    (###Log True values SheetName and Row Number to ErrorLog?)
                    
                End If
            Next cell
            
    Next Sh
            
            .Calculation = xlCalculationAutomatic
            .ScreenUpdating = True
        End With
        
    End Sub

In the example below row 2 is considered an error.

[TABLE="width: 500"]
[TR]
[TD]Row[/TD]
[TD]Column A[/TD]
[TD]Column B[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD] Allocation[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD][/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD] Benefit[/TD]
[TD]2[/TD]
[/TR]
[/TABLE]
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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