Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-12-2017, 11:15 AM
webba0264 webba0264 is offline Timestamp Sub failing Windows 8 Timestamp Sub failing Office 2007
Novice
Timestamp Sub failing
 
Join Date: Jun 2016
Posts: 9
webba0264 is on a distinguished road
Default Timestamp Sub failing

Hello all,

Attached is an .xlsm with Sheet 1 (Accrual!) displaying a table that updates based on Sheet 2 (Catalog!). I pulled these 2 sheets from a larger Workbook to simplify the problem I've having.

If you view code for Accrual!, you can see the Sub I've written (with help from members here at MSOffice Forums). The timestamps no longer update when the table in Accrual! updates, and when I run the debugger this is what I see:

"Compile error.
Variable cannot be defined."

--------------------------------------------------------------------------------------

TotalEnrolled = Range("A17")
End Function


Public Function TotalComplete() As Long
TotalComplete = Range("L17")
End Function

=> Public Sub CheckForChanges()

Application.EnableEvents = False

If Range("A17") <> LastValue.Range("TotalEnrolledLast") Then
Application.EnableEvents = False
Range("A18") = Date + Time
LastValue.Range("TotalEnrolledLast") = Range("A17")
End If

If Range("L17") <> LastValue.Range("TotalCompleteLast") Then
Range("L18") = Date + Time
LastValue.Range("TotalCompleteLast") = Range("L17")
End If

Application.EnableEvents = True
---------------------------------------------------------------------------------

Any help understanding the problem here would be greatly appreciated. Thanks in advance!

-AW
Attached Files
File Type: xlsm Book1_TimestampFail.xlsm (73.6 KB, 10 views)
Reply With Quote
  #2  
Old 04-12-2017, 02:56 PM
macropod's Avatar
macropod macropod is offline Timestamp Sub failing Windows 7 64bit Timestamp Sub failing Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

The reason you're getting such errors is that you have 'Option Explicit' set (good) but you haven't declared the variables before using them (bad) - which 'Option Explicit' requires. If you check the debugger, you'll see that 'LastValue' causes the error. Nowhere have you declared LastValue and neither have you given it a value. At a guess, I'd say it should be a worksheet reference. Similarly, the same line refers to a range named 'TotalEnrolledLast' but that range doesn't exist in the workbook - and neither does 'TotalCompleteLast'.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 04-13-2017, 07:11 AM
webba0264 webba0264 is offline Timestamp Sub failing Windows 8 Timestamp Sub failing Office 2007
Novice
Timestamp Sub failing
 
Join Date: Jun 2016
Posts: 9
webba0264 is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
The reason you're getting such errors is that you have 'Option Explicit' set (good) but you haven't declared the variables before using them (bad) - which 'Option Explicit' requires. If you check the debugger, you'll see that 'LastValue' causes the error. Nowhere have you declared LastValue and neither have you given it a value. At a guess, I'd say it should be a worksheet reference. Similarly, the same line refers to a range named 'TotalEnrolledLast' but that range doesn't exist in the workbook - and neither does 'TotalCompleteLast'.
Okay, that makes sense macropod. Now for the stupid question...

...how does one declare a value? Ex. "LastValue"

Someone helped me write this code, I am going to try and learn how to fix it.

Thank you MP
Reply With Quote
  #4  
Old 04-13-2017, 09:09 PM
macropod's Avatar
macropod macropod is offline Timestamp Sub failing Windows 7 64bit Timestamp Sub failing Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by webba0264 View Post
...how does one declare a value? Ex. "LastValue"
Assuming LastValue is a worksheet reference, you'd do that with code like:
Dim LastValue As Worksheet
then you need to tell VBA which worksheet LastValue refers to, using code like:
Set LastValue = Sheets("SomeWorksheetName")
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Timestamp Sub failing Timestamp Button Word Victora Word VBA 1 12-29-2012 08:47 AM
Timestamp appear in reading pane charlesmac Outlook 3 08-10-2012 02:16 AM
Using Date and Time (Timestamp) as a bullet m2oswald Word 1 02-07-2012 03:41 PM
Convert Timestamp to GMT Time SteadyWord Word 0 06-07-2010 06:38 AM
Timestamp for notes in contacts? boe Outlook 2 11-30-2005 04:19 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:06 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft