Rant:是的,如果一直坚持我的东西的人告诉我为什么,以便我可以从你的回答中学习,那就太好了。不要只是投票并离开。这对任何人都没有帮助。
我正在尝试按行找到厚底边框的单元格。以下代码使我的整个工作簿停止响应,我必须重新启动它。请帮帮忙?
Sub FindThiccBottomBorder()
Dim ws2 As Worksheet
Set ws2 = Sheets(2)
Dim brng As Range
Set brng = ws2.Range("C13")
start:
If brng.Borders(xlEdgeBottom).Weight = xlMedium Then
On Error Resume Next
brng.FormulaR1C1 = "found it!"
Else
brng = brng.Offset(1)
GoTo start
End If
End Sub
答案 0 :(得分:1)
试试这个:
Dim ws As Worksheet
Dim brng As Range
Dim Last_Row As Long
Set ws = ThisWorkbook.Worksheets("My Sheet Name") '<-- Replace this with your sheet name
Set brng = ws.Range("C13")
Last_Row = brng.Row + ws.UsedRange.Rows.Count - 1
Do While brng.Row <= Last_Row
If brng.Borders(xlEdgeBottom).Weight = xlMedium Then
brng = "found it!"
Exit Sub
End If
Set brng = brng.Offset(1)
Loop
一些未经请求的建议:
答案 1 :(得分:1)
以下是执行相同过程的更好代码。
Dim rngBottom As Range
Set rngBottom = Range("C13")
Do Until rngBottom.Borders(xlEdgeBottom).Weight = xlMedium
Set rngBottom = rngBottom.Offset(1)
Loop
rngBottom.Value = "found it!"
答案 2 :(得分:-1)
这是我最初的问题的答案。
Sub FindThiccBottomBorder()
Dim ws2 As Worksheet
Set ws2 = Sheets("Sheet2")
Dim brng As Range
Set brng = ws2.Range("C13")
start:
If brng.Borders(xlEdgeBottom).Weight = xlMedium Then
brng.FormulaR1C1 = "found it!"
Exit Sub
Else
End If
set brng = brng.Offset(1)
GoTo start
End Sub