所有工作表的Excel边框

所有工作表的Excel边框,excel,cell,vba,Excel,Cell,Vba,我想知道是否有一个宏可以为所有单元格中包含任何文本的工作表添加经典边框 我试过录制宏,但不适用于所有工作表 Sub TheWall() Application.ScreenUpdating = False Dim lngLstCol As Long, lngLstRow As Long lngLstRow = ActiveSheet.UsedRange.Rows.Count lngLstCol = ActiveSheet.UsedRange.Columns.Count For Each r

我想知道是否有一个宏可以为所有单元格中包含任何文本的工作表添加经典边框

我试过录制宏,但不适用于所有工作表

Sub TheWall()

Application.ScreenUpdating = False
Dim lngLstCol As Long, lngLstRow As Long

lngLstRow = ActiveSheet.UsedRange.Rows.Count
lngLstCol = ActiveSheet.UsedRange.Columns.Count

For Each rngCell In Range("A2:A" & lngLstRow)
    If rngCell.Value > "" Then
        r = rngCell.Row
        c = rngCell.Column
        Range(Cells(r, c), Cells(r, lngLstCol)).Select
            With Selection.Borders
                .LineStyle = xlContinuous
                .Weight = xlThin
                .ColorIndex = xlAutomatic
            End With
    End If
Next

Application.ScreenUpdating = True

End Sub
谢谢你的帮助

试试这个:

Sub TheWall()

    Application.ScreenUpdating = False

    Dim ws As Worksheet
    Dim rngCell As Range
    Dim hasValue As Boolean
    Dim r As Range

    For Each ws In ThisWorkbook.Worksheets

        For Each rngCell In ws.UsedRange
            hasValue = False
            For Each r In rngCell.MergeArea
                If r.Value <> "" Then
                    hasValue = True
                    Exit For
                End If
            Next r
            If hasValue Then
                With rngCell.Borders
                    .LineStyle = xlContinuous
                    .Weight = xlThin
                    .ColorIndex = xlAutomatic
                End With
            End If

        Next

    Next ws

    Application.ScreenUpdating = True
End Sub
Sub-TheWall()
Application.ScreenUpdating=False
将ws设置为工作表
Dim rngCell As范围
将值设置为布尔值
调光范围
对于此工作簿中的每个ws。工作表
对于ws.UsedRange中的每个rngCell
hasValue=False
对于rngCell.merge区域中的每个r
如果r.值为“”,则
hasValue=True
退出
如果结束
下一个r
如果有价值,那么
使用rngCell.Borders
.LineStyle=xlContinuous
.Weight=xlThin
.ColorIndex=xlAutomatic
以
如果结束
下一个
下一个ws
Application.ScreenUpdating=True
端接头

显示您的代码,请重复。我将我的报告添加到它中,但有些单元格没有边框。