|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub TEST2()
- '数字两位一组合并去掉邻位重复
- Dim arr, brr(), j, n, r, s, a, c, s1
- Application.ScreenUpdating = False
- With Worksheets("排列")
- r = .Range("CN1000000").End(xlUp).Row
- arr = .Range("CN1:CQ" & r)
- ReDim brr(1 To r, 1 To 1)
- For j = 3 To r
- s = arr(j, 1) & arr(j, 2) & arr(j, 3) & arr(j, 4)
- If Len(s) < 1 Then Exit For
- s1 = Left(s, 2)
- For n = 1 To Len(s) Step 2
- On Error Resume Next
- a = Right(s1, 2)
- c = Mid(s, n + 2, 2)
- s1 = Left(s1, Len(s1) - 2) & DELchong(a, c)
- Next
- brr(j, 1) = s1
- s1 = "": a = "": c = ""
- Next
- .Range("CS1:CS" & r).Select
- Selection.NumberFormatLocal = "@"
- .Range("CS:CS").ClearContents
- .Range("CS1").Resize(r, 1) = brr
- End With
- Application.ScreenUpdating = True
- End Sub
- Function DELchong(a, b)
- '2个数字比较,相同则去掉
- Dim i As String
- If a = b Then i = a '2者相同
- If a <> b Then i = a & b '2者不同
- DELchong = i
- End Function
复制代码
LED147258 发表于 2022-11-28 10:53
这FOR循环,我就存在一个死点,可能在两方面,1,不清晰循环的节奏,哪里开始哪里结束2,怎么读取数组。
...
我更新了回复,加上了我的代码,看起来更简单,不知是不是你想要的 |
|