+ Reply to Thread
Results 1 to 7 of 7

VBA Audit Trial for warehouse item manager

  1. #1
    Registered User
    Join Date
    08-26-2022
    Location
    Liverpool, England
    MS-Off Ver
    Office 365
    Posts
    10

    VBA Audit Trial for warehouse item manager

    I would greatly appreciate if somebody could help me make some changes to my current code VBA code.
    I've tried playing with it but can't make it work the way I want due to the fact that I now have multiple people doing changes to the data at the same time and it looks like the audit log code doesn't like this.

    The goal is to be able to use this with multiple people at the same time and record all the changes that occur to cells in the WH STOCK sheet and have them listed in the AUDIT LOG tab. Right now when 2 people are making a changes to the data audit records both of them and at the moment it freezes the sheet or kick other one out.

    Also is there a way to include a row deletion in the audit log? and be marked as some sort of event type, if the user changes any details I have "changed cell" as the event type which is just the text so the real question is if it's possible to have excel recognise those types of events.

    The short story is that I'm trying to create a temporary warehouse management system for multiple people to use prior to going into an advanced custom-built WMS system with scanners and all that and I am I noob with VBA stuff so still trying to learn a lot.

    Thank you in advance if anyone can help.

    This is the code that I am working right now.
    Private Sub Worksheet_Change(ByVal Target As Range)
    Dim i As Long, j As Long, k As Long, arr As Variant
    On Error GoTo ErrTrap:
    If Target.Areas.Count > 1 Then
    Application.EnableEvents = True
    MsgBox "sorry, you can change only one contignous range at once, old values restored", vbCritical
    Else
    If Target.Cells.Count > 1 Then
    arr = Target.Value
    Else
    ReDim arr(1 To 1, 1 To 1)
    arr(1, 1) = Target.Value
    End If
    Application.EnableEvents = False
    Application.Undo
    With Sheets("AuditLog")
    Sheets("AuditLog").Unprotect Password:="..."
    k = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
    For i = 1 To UBound(arr)
    For j = 1 To UBound(arr, 2)
    If arr(i, j) <> Target.Cells(i, j) Then
    Debug.Print Target.Cells(i, j).Address, Target.Cells(i, j), arr(i, j)
    .Cells(k, 1) = Application.UserName
    .Cells(k, 2).Value = Environ$("computername")
    .Cells(k, 3).Value = "changed cell"
    .Cells(k, 4).Value = Target.Cells(i, j).Address
    .Cells(k, 5).Value = Cells(Target.Cells(i, j).Row, "C").Value ' "To list referance to item code from column C"
    .Cells(k, 6).Value = Cells(Target.Cells(i, j).Row, "B").Value ' "To list referance to GRN from column B"
    .Cells(k, 7).Value = Cells(Target.Cells(i, j).Row, "D").Value ' "To list referance to LOT from column D"
    .Cells(k, 8).Value = Target.Cells(i, j)
    .Cells(k, 9).Value = arr(i, j)
    .Cells(k, 10).Value = Now()
    .Cells(k, 11).Value = ActiveSheet.Name
    k = k + 1
    End If
    Next j, i
    End With
    Application.Undo ' this will ReDo last UnDo in case if I forget later !!! :-) !!!
    Application.EnableEvents = True
    Sheets("AuditLog").Protect Password:="...", UserInterfaceOnly:=True
    Sheets("AuditLog").EnableAutoFilter = True
    Sheets("AuditLog").AllowSorting = True

    End If
    Exit Sub
    ErrTrap:
    ' keep events enabled reminder
    Application.EnableEvents = True
    ' other errors could be also handled here


    End Sub

  2. #2
    Registered User
    Join Date
    04-19-2021
    Location
    Dublin, Ireland
    MS-Off Ver
    O365, Win10 and Mac
    Posts
    47

    Re: VBA Audit Trial for warehouse item manager

    Could you upload the workbook (or relevant part thereof) so we can have a look? Also bear in mind that Excel is essentially a single user system so multiple users will not be able to update it contemporaneously unless you take special measures.

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    47,128

    Re: VBA Audit Trial for warehouse item manager

    If two or more people are accessing the file, how is it shared? What versions of Excel do all the users have? Where is the shared file's location?
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Registered User
    Join Date
    08-26-2022
    Location
    Liverpool, England
    MS-Off Ver
    Office 365
    Posts
    10

    Re: VBA Audit Trial for warehouse item manager

    Yes I do realise that Excel is mainly single user use but it has been ok so far with SharePoint sharing. However Access would be better fitted for this but it is also out of my league to build lol. Anyway this is the link for testing sheet
    TESTing.xlsmTESTing.xlsm

  5. #5
    Registered User
    Join Date
    08-26-2022
    Location
    Liverpool, England
    MS-Off Ver
    Office 365
    Posts
    10

    Re: VBA Audit Trial for warehouse item manager

    We are using Office 365 for business all updated to the latest version. As for sharing the file is being shared via SharePoint. So far there is no issues with that whatsoever as everything working as intended when audit code is not active. VBA code for audit only allows 1 person to make changes and I would like to change that to be more fluid but I don't know how exactly.

    This is testing copy of the sheet
    TESTing.xlsm

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    47,128

    Re: VBA Audit Trial for warehouse item manager

    As it's SharePoint and business related, it's outside my area of knowledge, so I regret I can be of little help.

    This link explains why you may get "Excel file is locked for editing":
    https://support.microsoft.com/en-us/...c-31b04aed68b3

    As for using VBA, I cannot advise. Historically, Excel was very bad at sharing files and the things you could do with VBA were very limited. I suspect that there may still be issues with certain constructs. For example, in a desktop based file, executing a macro would typically clear the Undo Stack, presumably because it is impossible to guess how many actions could be carried out by a macro so undoing them would be untenable.

    You are Unprotecting and protecting sheets which was also prohibited in the old style shared workbooks. AND you are trying to use Application.Undo. All potential issues in my mind.

    I can't find any definitive answer as to what you can and cannot do in a co-authored SharePoint based Excel file. Not to say it's nou out there; I just haven't found it.

    If you can, I would suggest you remove the unprotect/protect element, albeit temporarily, and also the Appliction.Undo, and see if that improves the situation.

    I don't have an environment to test any of this so I shall have to duck out.

    Good luck.

  7. #7
    Registered User
    Join Date
    04-19-2021
    Location
    Dublin, Ireland
    MS-Off Ver
    O365, Win10 and Mac
    Posts
    47

    Re: VBA Audit Trial for warehouse item manager

    You have made a lot of progress but I think there is still some way to go to get this working in a robust way. As TMS has pointed out, you will have issues with a number of aspects of your current approach. My own experience of shared workbooks is of horrendous file corruption, although that was with old-style file sharing which was just disastrous.

    I have something of an alternative, which I think covers most of what you are trying to achieve. I have written a generic form based data entry addin and have tweaked your sample file to work with it. If you install the attached addin (Dexel Form.xlam) it will create a separate ribbon in Excel which you can use to work with the updated sample file which I also attach. Documentation for the addin can be found via the link in About on the ribbon.
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] VBA Audit Trial for warehouse item manager
    By sk8_chris20 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-26-2022, 01:37 PM
  2. [SOLVED] add specific item into last item for whole item based on where precede item
    By ABDELFATTA in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-28-2022, 03:25 PM
  3. sales manager & purchase manager sheets command button error
    By rana19 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 05-24-2016, 07:26 AM
  4. [SOLVED] Formula for applying Audit trial
    By theprincesunil in forum Excel General
    Replies: 0
    Last Post: 09-23-2014, 03:05 PM
  5. Deleting item from name manager working intermittently
    By ks100 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-14-2014, 11:11 AM
  6. Replies: 3
    Last Post: 04-03-2008, 03:16 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1