首页 > 开发 > 综合 > 正文

在EXCEL中获取列中不重复的值的个数

2024-07-21 02:22:52
字体:
来源:转载
供稿:网友
public sub distinctcount()
'求col列中startrow到endrow范围中不重复的个数
'本例是计算标题为sheet1的excel表中的a1:a240的不重复值的个数
'修改下面四行的结尾值
dim sheetscaption as string: sheetscaption = "sheet1"
dim col as string: col = "a"
dim startrow as integer: startrow = 1
dim endrow as integer: endrow = 240
'以下固定
dim count as integer: count = 0
with sheets(sheetscaption)

for i = startrow to endrow
count = count + 1
for j = startrow to i - 1
if .range(col & i) = .range(col & j) then
count = count - 1
exit for
end if
next
next
end with
msgbox count
end sub

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表