来自不同工作表的VBA执行循环

时间:2019-02-01 16:00:31

标签: excel vba

我有一个带有引用活动单元格的循环的宏。当我构建代码时,这非常有效。但是,现在我整理这个excel模板,并尝试从另一个工作表(如菜单/控制表)中执行它。

除了在活动单元格上调用的部分之外,所有工作都使用带图纸工作。我有什么需要改变的吗?

With Sheets("EU Analysis")

        With .Range("C7:I5000")
            .Cells.ClearContents
            .Borders.LineStyle = xlNone
            .Interior.Color = 16777215
        End With

        With .Range("M7:Q21")
            .Cells.ClearContents
        End With

        With .Range("M23:N27")
            .Cells.ClearContents
        End With

        Dim r3 As Range
            Set r3 = .Range("C7:I7")
            r3.CopyFromRecordset rst4a

        Set r3 = .Range(r3, r3.End(xlDown).End(xlToRight))
         With r3
             .Borders(xlDiagonalDown).LineStyle = xlNone
             .Borders(xlDiagonalUp).LineStyle = xlNone
             .Borders(xlEdgeLeft).LineStyle = xlContinuous
             .Borders(xlEdgeRight).LineStyle = xlContinuous
             .Borders(xlEdgeTop).LineStyle = xlContinuous
             .Borders(xlEdgeBottom).LineStyle = xlContinuous
             .Borders(xlInsideVertical).LineStyle = xlContinuous
             .Borders(xlInsideHorizontal).LineStyle = xlContinuous
        End With

    RowCount = .Range("C" & Rows.Count).End(xlUp).Row - 6

        For i = 7 To RowCount + 6

            .Cells(i, 8).Select

            If ActiveCell.Value = "" Then
               ActiveCell.Value = "New"
               ActiveCell.HorizontalAlignment = xlCenter
               ActiveCell.Interior.Color = RGB(255, 192, 0)
            End If

        Next i

        For i = 7 To RowCount + 6

            .Cells(i, 7).Select

            If ActiveCell.Value = "" Then
               ActiveCell.Value = "Expired"
               ActiveCell.HorizontalAlignment = xlCenter
               ActiveCell.Interior.Color = RGB(141, 180, 226)
            End If

        Next i

End With

预先感谢

0 个答案:

没有答案