大家帮我看看这段代码,总是出错,不知道怎么修改,谢谢啦!
Sub 加红框2()
Dim ss As String
For i = 1 To 23
ss = Worksheets("机构名").Range("A" & i)
'机构名这张表里A1:A23是23个名称,分别对应workbook中的其中23个sheet.
k = worksheets(ss).Range("N2").Value
'这里N2里是行数,已经排除,问题不在这句
worksheets(ss).Range("A" & k & ":I" & k).Select
'这一句,如果用循环ss,就错,不用循环,单独一个一个机构操作此宏就没问题,现在认为问题就出在循环这,请高手帮我看看,非常感谢。
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = 3
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = 3
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = 3
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = 3
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Next i
End Sub