Hoppa till huvudinnehåll

Hur räknar man totalt antal klick i en angiven cell i Excel?

Den här artikeln talar om att räkna totalt antal klick i en specifik cell i Excel.

Räkna totalt antal klick i en angiven cell med VBA-kod


Räkna totalt antal klick i en angiven cell med VBA-kod

Gör så här för att räkna totalt antal klick i en viss cell i Excel.

1. I kalkylbladet innehåller cellen som du behöver för att räkna dess totala antal klick, högerklicka på arkfliken och klicka sedan på Visa kod från snabbmenyn.

2. I Microsoft Visual Basic för applikationer kopiera och klistra in under VBA-koden i kodfönstret.

VBA-kod: Räkna totalt antal klick i en angiven cell i Excel

Public xRgS, xRgD As Range
Public xNum As Long
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    On Error Resume Next
    If Target.Cells.Count > 1 Then Exit Sub
    Set xRgS = Range("E2")
    If xRgS Is Nothing Then Exit Sub
    Set xRgD = Range("H2")
    If xRgD Is Nothing Then Exit Sub
    If Intersect(xRgS, Target) Is Nothing Then Exit Sub
    xNum = xNum + 1
    xRgD.Value = xNum
End Sub

Anmärkningar: I koden är E2 cellen du behöver för att räkna dess totala klick, och H2 är utgångscellen för räkningen. Ändra dem efter behov.

3. tryck på andra + Q för att stänga Microsoft Visual Basic för applikationer fönster.

Från och med nu, när du klickar på cell E2 i det angivna kalkylbladet, fylls de totala klickarna automatiskt i cell H2 enligt nedanstående skärmdump. Om du till exempel klickar på cellen E2 fem gånger kommer nummer 5 att visas i cell H5.

Bästa kontorsproduktivitetsverktyg

🤖 Kutools AI Aide: Revolutionera dataanalys baserat på: Intelligent utförande   |  Generera kod  |  Skapa anpassade formler  |  Analysera data och generera diagram  |  Anropa Kutools funktioner.
Populära funktioner: Hitta, markera eller identifiera dubbletter   |  Ta bort tomma rader   |  Kombinera kolumner eller celler utan att förlora data   |   Rund utan formel ...
Superuppslag: Flera kriterier VLookup    VLookup med flera värden  |   VSök över flera ark   |   Fuzzy Lookup ....
Avancerad rullgardinslista: Skapa snabbt en rullgardinslista   |  Beroende rullgardinslista   |  Flervals-rullgardinslista ....
Kolumnhanterare: Lägg till ett specifikt antal kolumner  |  Flytta kolumner  |  Växla synlighetsstatus för dolda kolumner  |  Jämför intervall och kolumner ...
Utvalda funktioner: Rutnätsfokus   |  Designvy   |   Stor formelbar    Arbetsbok & Bladhanterare   |  Resursbibliotek (Automatisk text)   |  Datumväljare   |  Kombinera arbetsblad   |  Kryptera/Dekryptera celler    Skicka e-postmeddelanden efter lista   |  Superfilter   |   Specialfilter (filtrera fet/kursiv/genomstruken...) ...
Topp 15 verktygssatser12 text verktyg (lägga till text, Ta bort tecken, ...)   |   50+ Diagram Typer (Gantt Chart, ...)   |   40+ Praktiskt Formler (Beräkna ålder baserat på födelsedag, ...)   |   19 Införande verktyg (Infoga QR-kod, Infoga bild från sökväg, ...)   |   12 Konvertering verktyg (Siffror till ord, Valutaväxling, ...)   |   7 Slå ihop och dela verktyg (Avancerade kombinera rader, Dela celler, ...)   |   ... och mer

Uppgradera dina Excel-färdigheter med Kutools för Excel och upplev effektivitet som aldrig förr. Kutools för Excel erbjuder över 300 avancerade funktioner för att öka produktiviteten och spara tid.  Klicka här för att få den funktion du behöver mest...

Beskrivning


Fliken Office ger ett flikgränssnitt till Office och gör ditt arbete mycket enklare

  • Aktivera flikredigering och läsning i Word, Excel, PowerPoint, Publisher, Access, Visio och Project.
  • Öppna och skapa flera dokument i nya flikar i samma fönster, snarare än i nya fönster.
  • Ökar din produktivitet med 50 % och minskar hundratals musklick för dig varje dag!
Comments (31)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hi.
thanks for your amazing code.
as i use this, the counter get restarted every time i open the file,
is there any solution for this issue?
i need to see thclick counts in a larger time window

thanks in advance
This comment was minimized by the moderator on the site
Hi Mehrdad,
I am sorry to reply to you so late. The following code can help solve your problem. Every time you open the file, the counter will start counting from the last counted number.

Public xRgS, xRgD As Range
'Updated by Extendoffice 20230407
Public xNum As Long
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    On Error Resume Next
    If Target.Cells.Count > 1 Then Exit Sub
    Set xRgS = Range("E2")
    If xRgS Is Nothing Then Exit Sub
    Set xRgD = Range("H2")
    If xRgD Is Nothing Then Exit Sub
    If Intersect(xRgS, Target) Is Nothing Then Exit Sub
    xNum = xRgD.Value
    xNum = xNum + 1
    xRgD.Value = xNum
End Sub
This comment was minimized by the moderator on the site
Hola. Muchas gracias por los códigos.
Me gustaría saber cómo contar las veces que se hace clic sobre un enlace en una celda.
Muchas gracias.
This comment was minimized by the moderator on the site
Hi jose maria,
To count the clicks on a hyperlink, you can try the following VBA code.
Suppose hyperlinks are in column A and you want the number of clicks to be populated in the corresponding cell of column B (as shown in the screenshot below)
Please put the following code in the worksheet (code) window.

Private Sub Worksheet_FollowHyperlink(ByVal Target As Hyperlink)
'Updated by Extendoffice 20220805
    Dim Hyperlink As Range
    Set Hyperlink = Target.Range

    Hyperlink.Offset(0, 1) = Hyperlink.Offset(0, 1) + 1
End Sub

https://www.extendoffice.com/images/stories/comments/comment-picture-zxm/clicks_on_a_hyperlink.png
This comment was minimized by the moderator on the site
Bonjour ,
j'aimerai comment je pourrais le nombre de clics sur les cellules D10 à M10 et le retranscrire à la ligne R10 et le faire pour toutes les lignes suivante donc compter les clics sur les cellules D11 à M11 et le transcrire à la ligne R11 etc etc ?

Cordialement
This comment was minimized by the moderator on the site
Hi DUFOUR,
To count the number of clicks from D10 to M10 and output the total number of clicks in R10, you can apply the following VBA code to get it done.
Note: In the code, the range "D10:M30" means that the code only works from the row 10 to row 30, so please specify the rows you want to count.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Updated by Extendoffice 20220609
    Dim xNum As Long
    Dim xRgCount, xRg As Range
    
    On Error Resume Next
    If Target.Cells.Count > 1 Then Exit Sub

    Set xRg = Range("D10:M30")
    If Intersect(xRg, Target) Is Nothing Then Exit Sub
    Set xRgCount = Range("R" & Target.Row)
    
    If IsNumeric(xRgCount.Value) Then
        xNum = xRgCount.Value + 1
    Else
        xNum = 1
    End If
    xRgCount.Value = xNum
End Sub
This comment was minimized by the moderator on the site
Is there a way to backtrack the number count? For exemple: I'd made 5 clicks, but I just wanted 3. So I change the number in the cell to 3, and when I click again, it continues from 3. OR have the ability to press another cell and decrease the count by 1 if that is easier.
This comment was minimized by the moderator on the site
Hi, thank you for these VBA codes, they almost work for my needs. I fear the fact I need to go past double digits means it will not work. I need to have C8 through to C110 and the corresponding tally count being L8 through to L110. Can you help? Many thanks in advance.
This comment was minimized by the moderator on the site
Hi Andy,The following VBA code can do you a favor. Please have a try.<div data-tag="code">Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim xRgS, xRgD As Range
Dim xStrRg As String
Dim xCStr, xVStr As String
Dim xItem As Integer
xCStr = "C8:C110" 'The range of cells you want to record the clicks of each cell
xVStr = "L8:L110" 'The range of cells to place the records in
Set xRgS = Range(xCStr)
Set xRgD = Range(xVStr)
If Not (Intersect(xRgS, Target) Is Nothing) Then
xItem = Target.Row - xRgS.Item(1).Row + 1
xRgD.Item(xItem).Value = xRgD.Item(xItem).Value + 1
End If
End Sub
This comment was minimized by the moderator on the site
Hi, I'm trying to find a way of counting the number of times 20 different cells are being clicked (each one should be counted separately). I came across your VBA code suggestion, tried to adjust it to my specific needs but it won't work. can you please advise how the code should be written? the cells that I would like to count and the cells that the values should appear in are: F12>AU12, F13>AU13, G12>AV12, G13>AV13, H10>AW10, H11>AW11, H12>AW12, H13>AW13, H14>AW14, H15>AW15, I10>AX10, I11>AX11, I12>AX12, I13>AX13, I14>AX14, I15>AX15, J12>AY12, J13>AY13, K12>AZ12, K13>AZ13).
This is the VBA code I've tried with no success:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim xRgArray As Variant
Dim xNum
Dim xStrR, xStrS, xStrD As String
Dim xRgS, xRgD As Range

Dim xFNum As Long
xRgArray = Array("F12,AU12", "F13,AU13", "G12,AV12", "G13,AV13", "H10,AW10", "H11,AW11", "H12,AW12", "H13,AW13", "H14,AW14", "H15,AW15", "I10,AX10", "I11,AX11", "I12,AX12", "I13,AX13", "I14,AX14", "I15,AX15", "J12,AY12", "J13,AY13", "K12,AZ12", "K13,AZ13")
On Error Resume Next
If Target.Cells.Count > 1 Then Exit Sub
For xFNum = LBound(xRgArray) To UBound(xRgArray)
xStrR = xRgArray(xFNum)
xStrS = ""
xStrS = Left(xStrR, 2)
xStrD = ""
xStrD = Right(xStrR, 2)
Set xRgS = Nothing
Set xRgS = Range(xStrS)
If TypeName(xRgS) <> "Nothing" Then
Set xRgD = Nothing
Set xRgD = Range(xStrD)
If TypeName(xRgD) <> "Nothing" Then
If TypeName(Intersect(xRgS, Target)) <> "Nothing" Then
xRgD.Value = xRgD.Value + 1
End If
End If
End If
Next
End Sub

Thank you in advance, for your help.
This comment was minimized by the moderator on the site
Hi,The below code can help. Please have a try. Thank you.<div data-tag="code">Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim xRgS, xRgD As Range
Dim xStrRg As String
Dim xFNum As Integer
Dim xArr1, xArr2
If Target.Cells.Count > 1 Then Exit Sub
xStrRg = "F12-AU12; F13-AU13; G12-AV12; G13-AV13; H10-AW10; H11-AW11; H12-AW12; H13-AW13; H14-AW14; H15-AW15; I10-AX10; I11-AX11; I12-AX12; I13-AX13; I14-AX14; I15-AX15; J12-AY12; J13-AY13; K12-AZ12; K13-AZ13"
On Error Resume Next
xArr1 = Split(xStrRg, ";")
For xFNum = 0 To UBound(xArr1)
xArr2 = Split(xArr1(xFNum), "-")
Set xRgS = Range(xArr2(0))
Set xRgD = Range(xArr2(1))
If Not (Intersect(xRgS, Target) Is Nothing) Then
xRgD.Value = xRgD.Value + 1
End If
Next
End Sub
This comment was minimized by the moderator on the site
Crystal, The Above code is great for the sheet I am working with, thank you. But I have a question about adding a time macro so that everyday (excluding weekends) the tally moves to the next row in the sheet for example:

Row 3 - 7/1/2021 "B1-B3; C1-C3; D1-D3"
Row 4 - 7/2/2021 "B1-B4; C1-C4; D1-D4"
Row 5 - 7/3/2021 "B1-B5; C1-C5; D1-D5"

If this is possible? thx, Ken
This comment was minimized by the moderator on the site
The Above corrected code is great for the sheet I am working with, thank you. But I have a question about adding a time macro so that everyday (excluding weekends) the tally moves to the next row in the sheet for example:
Row 3 - 7/1/2021 "B1-B3; C1-C3; D1-D3"Row 4 - 7/2/2021 "B1-B4; C1-C4; D1-D4"Row 5 - 7/3/2021 "B1-B5; C1-C5; D1-D5"
This comment was minimized by the moderator on the site
Como zerar a contagem? How to reset the score?
This comment was minimized by the moderator on the site
Hi,
If you want to reset the counter, please add the below VBA code at the end of the original code which has been provided above, and then run it.

Sub ClearCount()
xRgD.Value = ""
xNum = 0
End Sub
This comment was minimized by the moderator on the site
Can you provide a code that allows counting clicks from A2, B2 cells through A14, B14 cells. Thanks in advance.
This comment was minimized by the moderator on the site
Hi Barbara,
Do you mean counting the total clicks in range A2:B14? Or clicks for each cell in range A2:B14?
This comment was minimized by the moderator on the site
Hola
Hay alguna manera de programar el conteo de clicks de acuerdo a la fecha, es decir programar varias celdas para que cuenten con la fecha del día?
This comment was minimized by the moderator on the site
Hello, there is a way to back the counting for any number that I want? For exemple: I'd made 5 clicks, but i just wanted 3. So I change the number in the cell to 3, and when I click again, it continue from 3.
Thank for the code!
This comment was minimized by the moderator on the site
Hi,
Sorry can’t help you with this, welcome to post any question about Excel to our forum: https://www.extendoffice.com/forum.html. You will get more Excel supports from our professional or other Excel fans.
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations