首页 > 解决方案 > 循环/复制/粘贴

问题描述

我在下面添加了一段代码到已经存在的代码中,好消息是它可以工作!坏消息是它确实放慢了宏观经济的速度。想知道是否有什么我可以做的不同的事情来让这个运行得更快。

我正在尝试遍历工作簿中的所有工作表,在范围(LastRow x LastColumn)中搜索“X”,如果我想粘贴值“X”的单元格中有“X”。

谢谢!乔什

For Each y In SubAssyArray
 Sheets(y).Activate
 Set ws = ActiveSheet
 Set StartCell = Cells(12, 10) 'Cell J12
 LastRow = ws.Cells(ws.Rows.Count, StartCell.Column).End(xlUp).Row
 LastColumn = ws.Cells(StartCell.Row, ws.Columns.Count).End(xlToLeft).Column - 3 '-3 columns to not count need date or ECD info
    For i = 10 To LastColumn 'Set from which column number you want the loop to start from
        For j = 12 To LastRow
            If Cells(j, i).Value = "X" Then
                Cells(j, i).Copy
                Cells(j, i).PasteSpecial xlPasteValues
                Else
            End If
        Next j
    Next i
Next y

标签: excelvbaloopscopy-paste

解决方案


推荐阅读