Fix to increment on Audit page Excel 365

DThib

Active Member
Joined
Mar 19, 2010
Messages
464
Office Version
  1. 365
Platform
  1. Windows
Hello all,
I have the code doing what I want but cannot get the information that should paste over to the Audit Trail page table to add another row. It copies over a cell already containing previous data.
Help, please!!!

VBA Code:
Dim PreviousValue
Private Sub Worksheet_Change(ByVal Target As Range)

Dim i As Long
Dim ws As Worksheet

Set ws = Sheets("Audit Trail")

i = ws.Range("A" & Rows.Count).End(xlUp).Row + 1

If Target.Value <> PreviousValue Then
    With ws
        .Range("B" & i).Value = FormatDateTime(Now, vbShortDate)
        .Range("C" & i).Value = FormatDateTime(Now, vbLongTime)
        .Range("D" & i).Value = Environ$("username")
        .Range("E" & i).Value = ActiveSheet.Name
        .Range("F" & i).Value = Target.Address
        .Range("G" & i).Value = PreviousValue
        .Range("H" & i).Value = Target.Value
    End With
End If

End Sub
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
Any help?
I need to audit trail several sheets in a workbook for any changes. My code replaces the same cell of information. I cannot remember how to have the next available be filled.
 
Upvote 0
There probably isn't enough information contained in your post to help us debug your issue.

Can you answer/include the following?
1. What sheet module is this code found in?
2. Can you post the code for the "Previous Value" calculation?
3. Can you show us some sample data and your expected output?
 
Upvote 0
There probably isn't enough information contained in your post to help us debug your issue.

Can you answer/include the following?
1. What sheet module is this code found in?
2. Can you post the code for the "Previous Value" calculation?
3. Can you show us some sample data and your expected output?
Hi,

I have it in 3 sheets I need to audit. So, the code is repeated 3 times.

VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
  
   PreviousValue = Target.Value
  
End Sub

Expected
1680632973420.png

From sheets with this setup
ManufacturerItemModelSerialCalibration Due DateWks before dueInterval (Months)Current TechLast TechTemp. PossessionOut for Cal.Returned from Cal.Cal Turn around WeeksAvailable? (in-house)Not scannedReplaceCalibration SourceComments
Fluke BiomedicalElectrical Safety Test MeterESA 620xxxxxx7-Jun-2023912T. W.
31-Mar-2023​
NoNot scannedOut for Calibration
Fluke BiomedicalElectrical Safety Test MeterESA 620xxxxx3-Aug-20231712D. G.Nox
 
Upvote 0
I think I might see where you problem is.
You see to be using column "A" on your "Audit Sheet" to find the last row with data, but you only appear to be updating columns B-H.
You should use a column that will ALWAYS have data in it to determine where the last row of data exists.

So if you change this line:
Rich (BB code):
i = ws.Range("A" & Rows.Count).End(xlUp).Row + 1
to this:
Rich (BB code):
i = ws.Range("B" & Rows.Count).End(xlUp).Row + 1
see if that fixes your issue.
 
Upvote 0
Solution
You are welcome.
Glad I was able to help.
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,195
Members
453,021
Latest member
pingpong7117

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