Incorporating functions in a change object sheet

EinarOSies

Board Regular
Joined
Feb 15, 2021
Messages
61
Office Version
  1. 2019
Platform
  1. Windows
I am trying to incorporate some function codes into a sheet change procedure module. The function are





VBA Code:
Function LastSaveDate() As Date

LastSaveDate = ActiveWorkbook.BuiltinDocumentProperties("Last Save Time")

End Function



Function LastSavedBy()

LastSavedBy = ThisWorkbook.BuiltinDocumentProperties("Last Author")

End Function



Function ExcelAuthor()

Excel Author = ThisWorkbook.BuiltinDocumentProperties("Author")

End Function



Function ExcelFileSize()

ExcelFileSize = FileLen(ThisWorkbook.FullName)

End Function



And the change procedure  code is

Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("C3:O39")) Is Nothing Then
On Error Resume Next

If Target.Value = "" Then
Range("C3:O39").Value = ""

Else

Range("M6").Value = LastSaveDate

End If

End If

If Not Intersect(Target, Range("C3:O39")) Is Nothing Then
On Error Resume Next

If Target.Value = "" Then
Range("C3:O39").Value = ""

Else

Range("N7").Value = LastSavedBy

End If

End If

If Not Intersect(Target, Range("C3:O39")) Is Nothing Then
On Error Resume Next

If Target.Value = "" Then
Range("C3:O39").Value = ""

Else

Range("I7").Value = ExcelFileSize

End If

End If
End Sub
When I make a change in the sheet it closes excel.
Please I don't know what is wrong with my code, please any help!!!
 
Last edited by a moderator:

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Hi & welcome to MrExcel.
How about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Not Intersect(Target, Range("C3:O39")) Is Nothing Then
      If Target.Value = "" Then
         Range("C3:O39") = ""
      Else
         On Error GoTo Xit
         Application.EnableEvents = False
         Range("M6").Value = LastSaveDate
         Range("N7").Value = LastSavedBy
         Range("I7").Value = ExcelFileSize
         Application.EnableEvents = True
      End If
   End If
Xit:
   Application.EnableEvents = True
End Sub
 
Upvote 0
Hi & welcome to MrExcel.
How about
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
   If Target.CountLarge > 1 Then Exit Sub
   If Not Intersect(Target, Range("C3:O39")) Is Nothing Then
      If Target.Value = "" Then
         Range("C3:O39") = ""
      Else
         On Error GoTo Xit
         Application.EnableEvents = False
         Range("M6").Value = LastSaveDate
         Range("N7").Value = LastSavedBy
         Range("I7").Value = ExcelFileSize
         Application.EnableEvents = True
      End If
   End If
Xit:
   Application.EnableEvents = True
End Sub
Mmm it still closes
 
Upvote 0
Did you delete your existing change event & paste my code in?
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,213,494
Messages
6,113,986
Members
448,538
Latest member
alex78

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