|
![](https://clubstatic.excelhome.net/image/common/ico_lz.png)
楼主 |
发表于 2024-5-27 14:55
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Public Sub bidui()
Dim irow As Integer, kl As Integer, jcol As Integer, kcol As Integer
Range("L76:BS116").ClearContents
irow = 9
' 循环到最后一行非空行
Do While Cells(irow, 9) <> ""
kl = 1
jcol = 8
' 朝左侧比对下有几个相同的
Do While Cells(irow, jcol) = Cells(irow, 9) '单元格(irow=9,jcol=8)=cells(9,9)
kl = kl + 1
jcol = jcol - 1
Loop
' 循环右边每一列
For kcol = 12 To 60 '从12列至71列
If Cells(irow, kcol) = Cells(irow, 9) Then
If kl > 1 Then
Cells(irow + 53, kcol) = Cells(irow, 9) & ".L" & kl '从irow+往下数要比对几行
Else: Cells(irow + 53, kcol) = Cells(irow, 9)
End If
End If
Next kcol
irow = irow + 1
Loop
Call hong4
End Sub
Sub hong4()
Range("L76:BS116").SpecialCells(xlCellTypeBlanks).Delete Shift:=xlUp
Range("L76:BS116").Select '排序的区域
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
End Sub
|
|