Recording multiple event details to same row

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,311
Office Version
  1. 2016
Platform
  1. Windows
I'm using this to record an event;

Code:
Sub ErrorAUDIT(Evnt As String)
Application.ScreenUpdating = False
Set ws = Worksheets("Audit")
iRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
ws.Cells(iRow, 1).Value = Now
ws.Cells(iRow, 2).Value = Evnt
ws.Cells(iRow, 3).Value = evnt2
ws.Cells(iRow, 4).Value = Evnt3
ws.Cells(iRow, 5).Value = Evnt4
ws.Cells(iRow, 6).Value = Evnt5
Application.ScreenUpdating = True
End Sub

and this to call the event, which is triggered by a compile error;

Code:
Dim Evnt As String
Evnt = "Program Error"
evnt2 = ErrNo
Evnt3 = strDescription
Evnt4 = strProcedure
Evnt5 = ErrLine
Call ErrorAUDIT(Evnt)

My issue is that it is only recording the Evnt and not the others - can someone show me what I need to do please to get it to record all of the error details?
 

Some videos you may like

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
6,082
Office Version
  1. 2019
Platform
  1. Windows
Hi,
looking at your code you are only passing one of the variables to your ErrorAUDIT procedure as an argument.
You can pass all the other variables using a ParamArray as your argument.

Code:
Sub ErrorAUDIT(ParamArray Evnt() As Variant)
Application.ScreenUpdating = False
Set ws = Worksheets("Audit")
iRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
ws.Cells(iRow, 1).Value = Now
ws.Cells(iRow, 2).Value = Evnt(0)
ws.Cells(iRow, 3).Value = Evnt(1)
ws.Cells(iRow, 4).Value = Evnt(2)
ws.Cells(iRow, 5).Value = Evnt(3)
ws.Cells(iRow, 6).Value = Evnt(4)
Application.ScreenUpdating = True
End Sub


Code:
Dim Evnt As String
Evnt = "Program Error"
Evnt2 = ErrNo
Evnt3 = strDescription
Evnt4 = strProcedure
Evnt5 = ErrLine
Call ErrorAUDIT(Evnt, Evnt2, Evnt3, Evnt4, Evnt5)


above is untested but hopefully, will do what you want.

You may also want to have a look here:https://forums.windowssecrets.com/s...-to-create-log-file-when-runtime-error-occurs
which you may find of interest.

Dave
 

Watch MrExcel Video

Forum statistics

Threads
1,108,621
Messages
5,523,947
Members
409,543
Latest member
LaMaqu1na

This Week's Hot Topics

Top