|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
- Sub test()
- Dim r%, i%
- Dim arr, brr
- Dim d As Object
- Set d = CreateObject("scripting.dictionary")
- With Worksheets("库存实时查询")
- r = .Cells(.Rows.Count, 2).End(xlUp).Row
- arr = .Range("a2:m" & r)
- For i = 1 To UBound(arr)
- d(arr(i, 5)) = arr(i, 8)
- Next
- End With
- With Worksheets("日常申购")
- r = .Cells(.Rows.Count, 2).End(xlUp).Row
- .Range("g4:j" & r).ClearContents
- arr = .Range("b4:j" & r)
- For i = 1 To UBound(arr)
- If d.exists(arr(i, 2)) Then
- arr(i, 6) = d(arr(i, 2))
- End If
- Next
- For i = 1 To UBound(arr)
- arr(i, 7) = arr(i, 6) - arr(i, 5)
- Next
- .Range("b4:j" & r) = arr
- For i = 1 To UBound(arr)
- If arr(i, 6) >= arr(i, 5) Then
- .Cells(i + 3, 8).Interior.ColorIndex = 4
- Else
- .Cells(i + 3, 8).Interior.ColorIndex = 3
- End If
- Next
- .Range("b3:j" & r).Sort key1:=.Range("h4"), order1:=xlAscending, Header:=xlYes
- End With
-
- End Sub
复制代码 |
|