宏选择和范围,更改格式,偏移然后循环

时间:2015-04-30 16:28:50

标签: excel vba excel-vba

我有一张2010年Excel表格,基本上有80张相同的"页面"每行30行。有一系列以" K126:N130和#34;我需要关闭此范围的文本换行,然后重复以下79"页面"并停在第2520行 我不熟悉"直到"但这是我到目前为止所拥有的。 感谢

Sub formatchange()
'
' formatchange Macro
'
Range("K126:N130").Select
With Selection
    .VerticalAlignment = xlBottom
    .WrapText = False
    .Orientation = 0
    .AddIndent = False
    .IndentLevel = 0
    .ShrinkToFit = False
    .ReadingOrder = xlContext
End With
ActiveSheet.Range("K126:N130").Offset(30).Select
With Selection
    .VerticalAlignment = xlBottom
    .WrapText = False
    .Orientation = 0
    .AddIndent = False
    .IndentLevel = 0
    .ShrinkToFit = False
    .ReadingOrder = xlContext
End With
End Sub

1 个答案:

答案 0 :(得分:1)

试试这个:

Sub formatchange()

    Dim rng As Range

    Set rng = ActiveSheet.Range("K126:N130")

    do while rng.cells(1).row < 2520

    With rng
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
    End With

    Set rng = rng.offset(30,0)

    Loop

End Sub