|
代码如下。。。
Sub test()
Dim rng As Range
Set wb = ThisWorkbook
Set sht = wb.Sheets("表一")
Set ws = wb.Sheets("sheet1")
r = sht.Cells(Rows.Count, 1).End(3).Row
'_______________________________________________________________________________________
' For i = r To 2 Step -1 '此代码为了删除多余的合并单元格(有些后面有合并行,有些后面又没有),否则step不能准确对准行号,用完,可以注释掉
' If sht.Cells(i, 1).MergeCells Then
' x = sht.Cells(i, 1).MergeArea.Address
' If (InStr(x, "$A$") > 0) And (InStr(x, "$L$") > 0) Then
' If rng Is Nothing Then Set rng = Rows(i) Else Set rng = Union(rng, Rows(i))
' End If
' End If
' Next
' rng.Delete
'_________________________________________________________________________________________
arr = ws.[a1].CurrentRegion
brr = sht.Range("a1:l" & sht.Cells(Rows.Count, 1).End(3).Row)
For i = 4 To UBound(brr) Step 5
For j = 2 To UBound(brr, 2) Step 4
If brr(i, j) <> Empty Then
sht.Cells(i, j).Interior.ColorIndex = 3
brr(i + 2, j) = Application.VLookup(brr(i, j), arr, 2, 0)
sht.Cells(i + 2, j).Interior.ColorIndex = 6
End If
Next
Next
sht.Range("a1:l" & sht.Cells(Rows.Count, 1).End(3).Row) = brr
Beep
End Sub
|
|