Recording multiple event details to same row

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,422
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?
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
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
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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