• 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.

VBA Code - Create Log sheet (Errorlog) in case VBA Macro condition is not met

Surya_Suresh

New Member
Hello Team,
I have created the Macro and I am running multiple macro, if condition is not met then i am getting popup of error message, however i need to create error log sheet where all the errors can be captured in another sheet in case condition is not met. Below is the code for your reference. Appreciate your help

>>> use code - tags <<<
Code:
Sub COMBINE()
    Call GSTR1
    Call GSTR2
    Call GSTR3
    Call GSTR4
    Application.ScreenUpdating = False   
    ' Display a message when the task is completed
    MsgBox "Validation done successfully!", vbInformation
End Sub

Sub GSTR1()
    Dim lastRow As Long
    Dim i As Long
    lastRow = Cells(Rows.Count, 9).End(xlUp).Row ' Assuming data starts from row 1
    For i = 9 To lastRow
        If Not IsEmpty(Range("A" & i).Value) And IsEmpty(Range("BL" & i).Value) Then
            MsgBox "Blank cell in column BL at cell BL" & i & ""
        End If
    Next i
End Sub

Sub GSTR2()
    Dim lastRow As Long
    Dim i As Long
    lastRow = Cells(Rows.Count, 9).End(xlUp).Row ' Assuming data starts from row 1   
    For i = 9 To lastRow
        If (Range("C" & i).Value = "EXWOP" Or Range("C" & i).Value = "EXWP") And Range("AJ" & i).Value = "G" Then
            If IsEmpty(Range("AC" & i).Value) Or IsEmpty(Range("AD" & i).Value) Or IsEmpty(Range("AE" & i).Value) Then
                MsgBox "Blank cell(s) in columns AC, AD, or AE at row " & i & ""
            End If
        End If
    Next i
End Sub

Sub GSTR3()
    Dim lastRow As Long
    Dim i As Long   
    lastRow = Cells(Rows.Count, 9).End(xlUp).Row ' Assuming data starts from row 1
    For i = 9 To lastRow
        If Not IsEmpty(Range("A" & i).Value) And IsEmpty(Range("BB" & i).Value) Then
            MsgBox "Blank cell in column BB at cell BB" & i & ""
        End If
    Next i
End Sub

Sub GSTR4()
    Dim lastRow As Long
    Dim i As Long
    lastRow = Cells(Rows.Count, 9).End(xlUp).Row ' Assuming data starts from row 1   
    For i = 9 To lastRow
        If Not IsEmpty(Range("A" & i).Value) And IsEmpty(Range("AY" & i).Value) Then
            MsgBox "Blank cell in column AY at cell AY" & i & ""
        End If
    Next i
End Sub
 
Last edited by a moderator:
Back
Top