Skip i'r prif gynnwys

Sut i gyfrif cyfanswm y cliciau mewn cell benodol yn Excel?

Mae'r erthygl hon yn sôn am gyfrif cyfanswm cliciau mewn cell benodol yn Excel.

Cyfrif cyfanswm y cliciau mewn cell benodol gyda chod VBA


Cyfrif cyfanswm y cliciau mewn cell benodol gyda chod VBA

Gwnewch fel a ganlyn i gyfrif cyfanswm y cliciau mewn cell benodol yn Excel.

1. Yn y daflen waith mae'n cynnwys y gell mae angen i chi gyfrif cyfanswm ei chliciau, de-gliciwch y tab dalen, ac yna cliciwch Gweld y Cod o'r ddewislen cyd-destun.

2. Yn y Microsoft Visual Basic ar gyfer Ceisiadau ffenestr, copïwch a gludwch islaw'r cod VBA i mewn i ffenestr y Cod.

Cod VBA: Cyfrif cyfanswm y cliciau mewn cell benodol yn 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

Nodyn: Yn y cod, E2 yw'r gell sydd ei hangen arnoch i gyfrif cyfanswm ei chliciau, a H2 yw cell allbwn y cyfrif. Newidiwch nhw yn ôl yr angen.

3. Gwasgwch y Alt + Q allweddi i gau'r Microsoft Visual Basic ar gyfer Ceisiadau ffenestr.

O hyn ymlaen, wrth glicio ar gell E2 yn y daflen waith benodol hon, bydd cyfanswm y cliciau yn cael eu poblogi'n awtomatig yng nghell H2 fel y dangosir isod y screenshot. Er enghraifft, os cliciwch ar y gell E2 5 gwaith, bydd rhif 5 yn cael ei arddangos yng nghell H2.

Offer Cynhyrchiant Swyddfa Gorau

🤖 Kutools AI Aide: Chwyldro dadansoddi data yn seiliedig ar: Cyflawniad Deallus   |  Cynhyrchu Cod  |  Creu Fformiwlâu Personol  |  Dadansoddi Data a Chynhyrchu Siartiau  |  Invoke Swyddogaethau Kutools...
Nodweddion Poblogaidd: Darganfod, Amlygu neu Adnabod Dyblygiadau   |  Dileu Rhesi Gwag   |  Cyfuno Colofnau neu Gelloedd heb Colli Data   |   Rownd heb Fformiwla ...
Super-edrych: VLookup Meini Prawf Lluosog    VLookup Gwerth Lluosog  |   VLookup Ar Draws Taflenni Lluosog   |   Edrych Niwlog ....
Rhestr gwympo Uwch: Creu Rhestr Gollwng yn Gyflym   |  Rhestr Gollwng Dibynnol   |  Rhestr Gollwng Aml-ddewis ....
Rheolwr Colofn: Ychwanegu Nifer Penodol o Golofnau  |  Symud Colofnau  |  Toglo Statws Gwelededd Colofnau Cudd  |  Cymharwch Ystodau a Cholofnau ...
Nodweddion dan Sylw: Ffocws ar y Grid   |  Golwg Dylunio   |   Bar Fformiwla Mawr    Rheolwr Llyfr Gwaith a Thaflen   |  Llyfrgell Adnoddau (Testun Auto)   |  Dewiswr Dyddiad   |  Cyfuno Taflenni Gwaith   |  Amgryptio/Dadgryptio Celloedd    Anfon E-byst trwy Restr   |  Hidlo Super   |   Hidlo Arbennig (hidlo mewn print trwm/italig/strikethrough...) ...
15 Set Offer Gorau12 Testun offer (Ychwanegu Testun, Dileu Cymeriadau,...)   |   50 + Siart Mathau (Siart Gantt,...)   |   40+ Ymarferol Fformiwlâu (Cyfrifwch oedran yn seiliedig ar ben-blwydd,...)   |   19 mewnosod offer (Mewnosod Cod QR, Mewnosod Llun o'r Llwybr,...)   |   12 Trosi offer (Rhifau i Eiriau, Trosi arian cyfred,...)   |   7 Uno a Hollti offer (Rhesi Cyfuno Uwch, Celloedd Hollt,...)   |   ... a mwy

Supercharge Eich Sgiliau Excel gyda Kutools ar gyfer Excel, a Phrofiad Effeithlonrwydd Fel Erioed Erioed. Kutools ar gyfer Excel Yn Cynnig Dros 300 o Nodweddion Uwch i Hybu Cynhyrchiant ac Arbed Amser.  Cliciwch Yma i Gael Y Nodwedd Sydd Ei Angen Y Mwyaf...

Disgrifiad


Mae Office Tab yn dod â rhyngwyneb Tabbed i Office, ac yn Gwneud Eich Gwaith yn Haws o lawer

  • Galluogi golygu a darllen tabbed yn Word, Excel, PowerPoint, Cyhoeddwr, Mynediad, Visio a Phrosiect.
  • Agor a chreu dogfennau lluosog mewn tabiau newydd o'r un ffenestr, yn hytrach nag mewn ffenestri newydd.
  • Yn cynyddu eich cynhyrchiant 50%, ac yn lleihau cannoedd o gliciau llygoden i chi bob dydd!
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