|
楼主 |
发表于 2023-1-15 00:54
|
显示全部楼层
Sub ykcbf() '//2023.1.13
Dim arr, brr, crr, str
str = [{"待安排","待审批"}]
If MsgBox("确定要结转至下月吗?", vbYesNo) <> vbYes Then Exit Sub
With Sheets("1")
r = .Cells(.Rows.Count, "a").End(xlUp).Row
c = .Cells(2, Columns.Count).End(xlToLeft).Column
arr = .Range("a3", .Cells(r, c))
End With
ReDim brr(1 To UBound(arr), 1 To UBound(arr, 2))
ReDim crr(1 To UBound(arr), 1 To UBound(arr, 2))
For i = 1 To UBound(arr)
s = arr(i, 8) '//条件区,这里可以多条件
If s <> Empty Then
For x = 1 To UBound(str)
If InStr(str(x), s) Then
m = m + 1
For j = 1 To UBound(arr, 2)
brr(m, j) = arr(i, j)
Next
Exit For
End If
Next
End If
Next i
For i = 1 To UBound(arr)
s = arr(i, 8) '//条件区,这里可以多条件
If s <> Empty Then
If InStr(str(1), s) = 0 And InStr(str(2), s) = 0 Then
n = n + 1
For j = 1 To UBound(arr, 2)
crr(n, j) = arr(i, j)
Next
Exit For
End If
End If
Next i
With Sheets("2")
.Rows("3:22").ClearContents
If m > 0 Then .[a3].Resize(m, UBound(brr, 2)) = brr
End With
MsgBox ("结转完成")
' With Sheets("1")
' .Rows("3:22").ClearContents
' If n > 0 Then .[a3].Resize(n, UBound(crr, 2)) = crr
' End With
End Sub
此过程只是实现了sheets("1")结转数据到sheets("2") 如果是1-12月份,12个工作表,怎么写通用的sub
|
|