|
将以下代码COPY到你的文件中,运行即可。至于颜色,更改ColorIndex号码到你想要的颜色。Sub StockReconcillation()
Dim i, xz, Line As Integer
Dim PN As String
Line = 0
Range("A1").Select
PN = Left(Selection, 9)
ActiveCell.SpecialCells(xlLastCell).Select
xz = ActiveCell.Row
For i = 2 To xz + 1
Range("A" & i).Select
If PN = Left(Selection, 9) Then
Line = Line + 1
'MsgBox " Line is " & Line
Else
'MsgBox "Change PN " & i
PN = Left(Selection, 9)
If Line <> 0 Then
Range("A" & i - 1 - Line & ":I" & i - 1).Select
With Selection.Interior
.ColorIndex = 43
.Pattern = xlSolid
End With
Line = 0
End If
End If
Next
End Sub |
|