|
楼主 |
发表于 2016-8-29 10:38
|
显示全部楼层
Sub zj()
Sheets("取得").Activate
Call 增加
Sheets("移動").Activate
Call 增加
Sheets("廃棄").Activate
Call 减少
Sheets("返却").Activate
Call 减少
Sheets("仕損").Activate
Call 减少
End Sub
Sub 增加()
Dim brr(), arr(), dic As Object, i As Long, j As Long, a
Set dic = CreateObject("scripting.dictionary")
brr = Sheets("固定資産管理台帳").Range(Sheets("固定資産管理台帳").[d2], Sheets("固定資産管理台帳").Cells(100000, 4).End(3)).Value
For i = 1 To Sheets("固定資産管理台帳").Cells(100000, 4).End(3).Row - 1
dic(brr(i, 1)) = i + 1
Next
On Error GoTo a
arr = ActiveSheet.Range([d2], Cells(1000000, 4).End(3)).Value
For j = 1 To ActiveSheet.Cells(1000000, 1).End(3).Row - 1
If dic.exists(arr(j, 1)) = False Then
ActiveSheet.Rows(j + 1).Copy Sheets("固定資産管理台帳").Cells(100000, 1).End(3).Offset(1, 0)
End If
Next
Exit Sub
a: If ActiveSheet.Cells(100000, 4).End(3).Row > 1 Then
ActiveSheet.Rows(2).Copy Sheets("固定資産管理台帳").Cells(100000, 1).End(3).Offset(1, 0)
End If
End Sub
Sub 减少()
Dim brr(), arr(), dic As Object, i As Long, j As Long, m As Long, a
Set dic = CreateObject("scripting.dictionary")
brr = Sheets("固定資産管理台帳").Range(Sheets("固定資産管理台帳").[d2], Sheets("固定資産管理台帳").Cells(100000, 4).End(3)).Value
For i = 1 To Sheets("固定資産管理台帳").Cells(100000, 4).End(3).Row - 1
dic(brr(i, 1)) = i + 1
Next
On Error GoTo a
arr = ActiveSheet.Range([d2], Cells(1000000, 4).End(3)).Value
For j = ActiveSheet.Cells(1000000, 1).End(3).Row - 1 To 1 Step -1
If dic.exists(arr(j, 1)) = True Then
Sheets("固定資産管理台帳").Rows(dic(arr(j, 1))) = ""
End If
Next
For m = Sheets("固定資産管理台帳").Cells(1000000, 1).End(3).Row To 2 Step -1
If Application.WorksheetFunction.CountA(Sheets("固定資産管理台帳").Rows(m)) = 0 Then
Sheets("固定資産管理台帳").Rows(m).Delete
End If
Next
Exit Sub
a: If ActiveSheet.Cells(100000, 4).End(3).Row > 1 Then
Sheets("固定資産管理台帳").Rows(dic(ActiveSheet.Cells(2, 4).Value)).Delete
End If
End Sub |
|