• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Log in separate sheet (with name, date and time)|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / Log in separate sheet (with name, date and time)|VBA & Macros|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumVBA & MacrosLog in separate sheet (with name, d…
sp_PrintTopic sp_TopicIcon
Log in separate sheet (with name, date and time)
Avatar
Azid Imdad
Member
Members
Level 0
Forum Posts: 15
Member Since:
February 21, 2018
sp_UserOfflineSmall Offline
1
March 29, 2021 - 7:55 pm
sp_Permalink sp_Print

Hi VBA Gurus,

I have created checklist with the help of checkboxes in excel sheet (office 365). I want to create log (in same workbook but separate sheet) to keep record of name of person ticked checkbox, time and date. 

I have used following code but is does not give date and time (copied code from somewhere)

Dim PreviousValue

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Value <> PreviousValue Then
Sheets("log").Cells(65000, 1).End(xlUp).Offset(1, 0).Value = _
Application.UserName & " changed cell " & Target.Address _
& " from " & PreviousValue & " to " & Target.Value
End If
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
PreviousValue = Target.Value

End Sub

 

Can someone please help how to do that. Excel workbook is attached. 

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
2
April 1, 2021 - 3:17 am
sp_Permalink sp_Print

To add date and time, replace:
Application.UserName & " changed cell " & Target.Address _
& " from " & PreviousValue & " to " & Target.Value

with:

Application.UserName & " changed cell " & Target.Address _
& " from " & PreviousValue & " to " & Target.Value & " at: " & Format(Now(),"yyyy-mm-dd-hh-mm-ss")

Avatar
Azid Imdad
Member
Members
Level 0
Forum Posts: 15
Member Since:
February 21, 2018
sp_UserOfflineSmall Offline
3
April 1, 2021 - 7:23 pm
sp_Permalink sp_Print

Hi Catalin, 

Thanks for your help . Code has worked for time and date . 

Two more things (if you can help please).

1- Log says "changed cell $E$10 from to test 5 on: 01-April-2021 at 20-16. It should say "changed cell $E$10 from empty to test 5 on: 01-April-2021 at 20-16

2- code does not log when tick "checkbox"

Thanks in anticipation. 

Regards, 

Azid 

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
4
April 2, 2021 - 2:40 am
sp_Permalink sp_Print sp_EditHistory

Hi Azid,

Instead of:
" from " & PreviousValue & " to " & Target.Value

use:

" from " & IIF(PreviousValue<>"",PreviousValue,"empty") & " to " & Target.Value

A checkbox change does not have an event associated, you cannot detect when there is a change. You have to right click the checkbox>Assign Macro>New.
A code is generated for that checkbox, put inside this code:
LogRow Application.Caller

Full procedure will look like:

Sub CheckBox7_Click()
LogRow Application.Caller
End Sub

All checkboxes will have the same code:

Sub CheckBox3_Click()
LogRow Application.Caller
End Sub

Here is the LogRow procedure:

Sub LogRow(ByVal Caller As String)
Dim Wks As Worksheet: Set Wks = ThisWorkbook.Worksheets("BAS-QTR")
Dim Cell As String: Cell = Wks.Shapes(Caller).ControlFormat.LinkedCell
Dim CBStatus As String
Sheets("log").Cells(65000, 1).End(xlUp).Offset(1, 0).Value = _
Application.UserName & " changed " & Caller & Wks.Range(Cell).Row _
& " from " & IIf(Wks.Range(Cell).Value = True, False, True) & " to " & Wks.Range(Cell).Value & " (" & Wks.Cells(Wks.Range(Cell).Row, "B").Value & ")"
End Sub
Avatar
Azid Imdad
Member
Members
Level 0
Forum Posts: 15
Member Since:
February 21, 2018
sp_UserOfflineSmall Offline
5
April 2, 2021 - 7:34 pm
sp_Permalink sp_Print

Hi Catalin, 

You are legend. 

Thanks. I will try and will let you if there is any issue. 

Kind regards, 

Azid 

Avatar
Azid Imdad
Member
Members
Level 0
Forum Posts: 15
Member Since:
February 21, 2018
sp_UserOfflineSmall Offline
6
April 3, 2021 - 1:40 pm
sp_Permalink sp_Print

Hi Catalin, 

VBA showing following error. can you please help. 

VBA-error-in-code.PNGImage Enlarger

sp_PlupAttachments Attachments
  • sp_PlupImage VBA-error-in-code.PNG (158 KB)
Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
7
April 3, 2021 - 5:26 pm
sp_Permalink sp_Print

At the end of my previous message, I provided the LogRow procedure, make sure you add it to your project. Not seeing it in your screen, that's also what the error says, it cannot find it.

Avatar
Azid Imdad
Member
Members
Level 0
Forum Posts: 15
Member Since:
February 21, 2018
sp_UserOfflineSmall Offline
8
April 6, 2021 - 6:26 pm
sp_Permalink sp_Print

Hi Catalin, 

Thanks the checkbox log is working now except "checkbox" number system showing is incorrect ( I have attached original sheet and made comments in Log sheet). 

Is is possible to add box assign macro so "If my boss clicket rechecked ROW 3 should protected (no one can make any change and color of the box should change to GREEN"

You are helping me a lot. I wish you guy teach JavaScript for excel automation also. 

Thanks in anticipation and kind regards, 

Azid 

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
9
April 7, 2021 - 1:59 am
sp_Permalink sp_Print

These lines needs to be changed:
Application.UserName & " changed " & Caller & " (row " & Wks.Range(Cell).Row & ") " _
& " from " & IIf(Wks.Range(Cell).Value = True, False, True) & " to " & Wks.Range(Cell).Value & " (" & Wks.Cells(Wks.Range(Cell).Row, "B").Value & ")"

I wish you guy teach JavaScript for excel automation also.

It's better to know as much as possible all excel normal tools before going to a complex automation. Many things can be done with normal excel tools, without any automation, excel has a lot of tools and features. Used properly, covers many needs. You need to learn JavaScript language, and that is not excel specific language. Once you know JS, using the specific office JS library will be a walk in the park.

I suggest using the right click event to hide the current row shape and change the cell color, see file attached.

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Lynnette Altomari, Sherry Fox, Riny van Eekelen, Dieneba NDIAYE, Tucker Oakley
Guest(s) 12
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 870
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Sopi Yuniarti
sandra parker
LAFONSO HERNANDEZ
Hayden Hao
Angela chen
Sean Moore
John Chisholm
vexokeb sdfg
John Jack
Malcolm Toy
Forum Stats:
Groups: 3
Forums: 24
Topics: 6214
Posts: 27243

 

Member Stats:
Guest Posters: 49
Members: 31894
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.