level 11
'用字典很简单,循环会复杂一点
Option Explicit
Sub test()
Dim arr, i, dic, t
Set dic = CreateObject("scripting.dictionary")
arr = Range("b6:b" & Cells(Rows.Count, "b").End(xlUp).Row)
For i = 1 To UBound(arr, 1)
dic(arr(i, 1)) = dic(arr(i, 1)) + 1
Next
For i = UBound(arr, 1) To 1 Step -1
t = arr(i, 1)
If dic(t) Then
arr(i, 1) = dic(t) & "次"
dic.Remove (t)
Else
arr(i, 1) = vbNullString
End If
Next
[c6].Resize(UBound(arr, 1), 1) = arr
End Sub
2018年02月11日 06点02分
4
level 15
=IF(B6=B7,"",COUNTIF(B:B,B6)&"次")
2018年02月11日 06点02分
5
大神啊 !小吧V5
2018年02月12日 15点02分
level 11
'给你用循环写个
Option Explicit
Sub test()
Dim arr, i, j, n
arr = Range("b6:b" & Cells(Rows.Count, "b").End(xlUp).Row + 1)
For i = 1 To UBound(arr, 1) - 1
For j = i To UBound(arr, 1) - 1
n = n + 1
If arr(j, 1) <> arr(j + 1, 1) Then
arr(j, 1) = n & "次": n = 0: i = j: Exit For
Else
arr(j, 1) = vbNullString
End If
Next j, i
[c6].Resize(UBound(arr, 1), 1) = arr
End Sub
2018年02月11日 06点02分
6
完全看不懂
![[笑尿]](/static/emoticons/u7b11u5c3f.png)
大概我所会的只有if for do之类最简单的。 话说我的那个问题出在哪呀
2018年02月11日 07点02分
@Alexsetsuna if a=b then 与紧接着的 do until a<>b本身就是矛盾的。你在数字3时之所以成立是因为只有2个数字3,当前一个条件成立时,此时处于第二个数字3,刚好紧接着的是数字4,所以第二个条件也成立。但在7这个位置就不行了,有连续的3个数字7,这两个条件不能同时满足的。
2018年02月11日 07点02分
@baifandu2013 可是按下面的代码稍加修改,if a=b和do until a<>b还是能用的呀。
2018年02月11日 08点02分
level 11
Option Explicit
Sub test()
Dim i, A, B, C, x As Integer
[c:c].ClearContents
i = 6
Do While i < 17
C = 0
A = Cells(i, "b")
B = Cells(i + 1, "b")
If A = B Then
Do Until A <> B
C = C + 1
B = Cells(i + C, "b")
Loop
Cells(i + C - 1, "c") = C & "次"
i = i + C
Else
Cells(i, "c") = 1 & "次"
i = i + 1
End If
Loop
End Sub
2018年02月11日 07点02分
8
原来是我太天真的以为B一直是i+2,正确的应该随着c变化的
2018年02月11日 08点02分
顺便,i=i+c,放在End If的后面,和放在then与else后面,区别是什么
2018年02月11日 08点02分
level 10
For双循环代码如下:
Sub 计数()
Dim i%, j%, t%, k%
For j = 1 To Cells(Rows.Count, 1).End(xlUp).Row
For i = 1 To Cells(Rows.Count, 1).End(xlUp).Row
If Cells(i, 1) = Cells(j, 1) Then
t = i
k = k + 1
End If
Next
Cells(t, 2) = k & "次"
k = 0
Next
End Sub
2018年02月11日 09点02分
12
level 10
这里你首先搞清楚几个概念,range.end(xlup)什么意思?
一般用range.end(xlup)那么数据源是连续的规则的数据(形象理解为完整的豆腐块儿,有一个空值,代表豆腐挖一个小口,不完整),即数据没有空值且可以变动(数据变动后也要求数据连续)。如果数据源不连续且是变动的,最好的做法是源数据单独一个工作表,汇总结果放入另外一个工作表,这样就可以用worksheet.usedrange来访问源数据。
2018年02月12日 02点02分
15