VBA help, recording the time and location of clicked cells

pltaine

New Member
Joined
May 9, 2018
Messages
8
Hi guys,

I am new to the whole VBA side of Excel and have hit a wall which requires superior knowledge.

What I am trying to do it create a 'log' sheet so that i can record which cells are clicked and at what time they are clicked. Consider this like a scoreboard for basketball. Everytime the home team score a point, I click on either the 1,2 or 3 cells B1, B2 and B3 respectively depending on how many points they scored. This would then add onto their total.

However after the game, I want to go back and see at what time the points were scored, and how many points were scored with that shot.

I have 2 different sheets, 1 for the clicking the cells to add the scores (which I have already put into the VBA code for the sheet) and another sheet to store the feed data with headings "Time" and "Cell". I can then fill in the rest of the feed grid by using vlookups.

Any ideas on how I can do this?

Note: Because of the nature of what I'm trying to do, the scores are added by clicking on the cells, they are not buttons with macros attached to them.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
place this code in the sheet you click:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column = 2 And Target.Row <= 3 Then
    With Sheets("Blad2")
    Lr = .Range("A" & Rows.Count).End(xlUp).Row + 1
        .Cells(Lr, 1) = Time
        .Cells(Lr, 2) = Target.Address
    End With
End If
End Sub

Change "Blad2" to the sheetname in which you store the feed

If you dont want the $$$ signs then use this one:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column = 2 And Target.Row <= 3 Then
    With Sheets("Blad2")
    Lr = .Range("A" & Rows.Count).End(xlUp).Row + 1
        .Cells(Lr, 1) = Time
        .Cells(Lr, 2) = Replace(Target.Address, "$", "")
    End With
End If
End Sub
 
Last edited:
Upvote 0
Thanks, this code looks good, however it has come up with Ambiguous name detected: Worksheet_SelectionChange.

Any ideas?
 
Upvote 0
I think the issue was I had 2 Selection changes in the same sheet, so I put them together and now it works great! Thanks for the help!
 
Upvote 0

Forum statistics

Threads
1,216,745
Messages
6,132,473
Members
449,729
Latest member
davelevnt

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