我有一份姓名列表,我想在列表旁边创建一个列,指示每个给定姓名在列表中的条目数。下面是我想要实现的示例,标题为“ENTRY”的列:
INDEX NAME ENTRY
1 MIKE 1
2 JANE 1
3 JANE 2
4 JANE 3
5 LANA 1
6 MIKE 2
7 JEREMY 1
8 CLIVE 1
9 JANE 4
我怎样才能实现这个目标?
答案1
这个 VBa 可以实现您想要的功能。
记得先备份文件,没有撤消功能
Option Explicit
Sub EeekPirates()
Dim startRow As Integer
startRow = 2 'Ah hoy cap'ain, enter the startRow
Dim entryColumn As String
entryColumn = "C" 'Enter the entry column so we can place the gold...
Dim nameColumn As String
nameColumn = "B" 'Enter the name column so we know the sea dogs name
'aye aye cap'ain, we'll start now. Touch any of the below and we'll feed ye to the sharks
Dim realStartRow As Integer
realStartRow = startRow
Dim innerRow As Integer
innerRow = startRow
Do While (Range(nameColumn & startRow).Value <> "")
Dim count As Integer
count = 0
Dim name As String
name = Range(nameColumn & startRow).Value
Do While (innerRow - 1 < startRow)
If (Range(nameColumn & innerRow).Value = name) Then
count = count + 1
End If
innerRow = innerRow + 1
Loop
Range(entryColumn & startRow).Value = count
innerRow = realStartRow
startRow = startRow + 1
Loop
End Sub
这是 VBa 执行后的屏幕截图