|
楼主 |
发表于 2021-6-23 11:40
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- [code]Sub test()
- On Error Resume Next
- Dim arr
- Dim i, j As Long
- arr = Sheet1.Range("a1:i" & Cells(Rows.Count, 1).End(xlUp).Row)
- For i = 1 To UBound(arr)
- For j = 1 To UBound(arr, 2)
- If IsError(arr(i, j)) Then
- arr(i, j) = ""
- Else
- arr(i, j) = arr(i, j)
- End If
- Next
- Next
- With Sheet1.Range("a1").Resize(UBound(arr), UBound(arr, 2))
- .NumberFormat = "@"
- .Value = arr
- End With
- End Sub
- Sub test1()
- Dim kk As Long
- On Error Resume Next
- Dim arr, brr, crr
- arr = Sheet1.Range("a1:i" & Cells(Rows.Count, 1).End(xlUp).Row)
- 'brr = Range("b1:b" & Cells(Rows.Count, 1).End(xlUp).Row)
- 'crr = Range("c1:c" & Cells(Rows.Count, 1).End(xlUp).Row)
- For j = 1 To UBound(arr, 2)
- kk = Sheet2.UsedRange.Rows.Count
- If j = 9 Then Exit Sub
- For i = 2 To UBound(arr)
- If arr(i, j) = 0 And arr(i, j + 1) = 0 Then
- x = x + 1
- End If
- If arr(i, j) = 0 And arr(i, j + 2) = 0 Then
- x1 = x1 + 1
- End If
- If arr(i, j) = 0 And arr(i, j + 3) = 0 Then
- x2 = x2 + 1
- End If
- If arr(i, j) = 0 And arr(i, j + 4) = 0 Then
- x3 = x3 + 1
- End If
- If arr(i, j) = 0 And arr(i, j + 5) = 0 Then
- x4 = x4 + 1
- End If
- If arr(i, j) = 0 And arr(i, j + 6) = 0 Then
- x5 = x5 + 1
- End If
- If arr(i, j) = 0 And arr(i, j + 7) = 0 Then
- x6 = x6 + 1
- End If
- If arr(i, j) = 0 And arr(i, j + 8) = 0 Then
- x7 = x7 + 1
- End If
- Next
- Sheet2.Range("a" & kk) = arr(1, j) & "为0" & "||" & arr(1, j + 1) & "为0"
- Sheet2.Range("b" & kk) = x
- Sheet2.Range("a" & kk + 1) = arr(1, j) & "为0" & "||" & arr(1, j + 2) & "为0"
- Sheet2.Range("b" & kk + 1) = x1
- Sheet2.Range("a" & kk + 2) = arr(1, j) & "为0" & "||" & arr(1, j + 3) & "为0"
- Sheet2.Range("b" & kk + 2) = x2
- Sheet2.Range("a" & kk + 3) = arr(1, j) & "为0" & "||" & arr(1, j + 4) & "为0"
- Sheet2.Range("b" & kk + 3) = x3
- Sheet2.Range("a" & kk + 4) = arr(1, j) & "为0" & "||" & arr(1, j + 5) & "为0"
- Sheet2.Range("b" & kk + 4) = x4
- Sheet2.Range("a" & kk + 5) = arr(1, j) & "为0" & "||" & arr(1, j + 6) & "为0"
- Sheet2.Range("b" & kk + 5) = x5
- Sheet2.Range("a" & kk + 6) = arr(1, j) & "为0" & "||" & arr(1, j + 7) & "为0"
- Sheet2.Range("b" & kk + 6) = x6
- Sheet2.Range("a" & kk + 7) = arr(1, j) & "为0" & "||" & arr(1, j + 4) & "为0"
- Sheet2.Range("b" & kk + 7) = x7
- x = 0
- x1 = 0
- x2 = 0
- x3 = 0
- x4 = 0
- x5 = 0
- x6 = 0
- x7 = 0
- Next
- x = 0
- y = 0
- Z = 0
- k = 0
- 'Debug.Print x, y, Z, k
- End Sub
复制代码
不好意思又打扰您了,想请问一下这段代码假如需要处理更多变量的话应该怎么继续添加语句呢?[/code] |
|