0

显然,我的代码中还没有必要的循环,但我想从第 3 行创建一个 Range("b3:gs3") 循环,并按照以下递归方式更新它:

Range("b3:gs3")
Range("b6:gs6")
Range("b9:gs9")
.
.
.
Range("b720:gs720")

我可以对循环进行编码,但是很难对范围值的这种变化进行编码。

帮助将不胜感激。

罗恩

Sub Box()

    Dim curCell3 As Range

    For Each curCell3 In Sheets("Sheet 2").Range("b3:gs3").Cells  'This is the problem

    ActiveWorkbook.Sheets("6").Activate
    Range("B1").Select

    Do While ActiveCell.Value <> curCell3.Value
        ActiveCell.Offset(0, 1).Select
    Loop

            ActiveCell.Offset(44, 0).Select
            ActiveCell.Copy
            ActiveWorkbook.Sheets("Sheet 2").Activate
            curCell3.Select
            ActiveCell.Offset(1, 0).Select
            ActiveCell.PasteSpecial Paste:=xlPasteValues

    Next curCell3

ActiveWorkbook.Sheets("6").Activate
Rows("3:3").Delete
ActiveCell.Offset(2, -199).Select

End Sub
4

1 回答 1

0
Sub Box()

    Dim curCell3 As Range
    Dim rw As Long, f As Range, rngSrch As Range

    Set rngSrch = ActiveWorkbook.Sheets("6").UsedRange.Columns(2)

    For rw = 3 To 720 Step 3

        For Each curCell3 In Sheets("Sheet 2"). _
             Range("b" & rw & ":gs" & rw).Cells

            Set f = rngSrch.Find(curCell3.Value, , xlValues, xlWhole)
            If Not f Is Nothing Then
                curCell3.Offset(0, 1).Value = f.Offset(44, 0).Value
            End If

        Next curCell3

    Next rw

End Sub
于 2013-02-11T06:27:56.963 回答