在我的宏循环中运行时错误1004

时间:2015-10-07 18:36:10

标签: excel excel-vba vba

'Declare Variables
Dim rng As Range
Dim AmQ As Worksheet, UpIss As Worksheet, QuMa As Worksheet

'Set your sheet names into variables for easier referencing
Set AmQ = Sheets("AMEND QUOTE")
Set UpIss = Sheets("UPISSUE")

For i = 7 To 57 '7 = Column H, 8 = Column G, etc.

'Set the address of the found value to the rng variable
Set rng = UpIss.Cells.Find(What:=AmQ.Cells(4, i).Value, After:=ActiveCell, LookIn:=xlValues, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)

If Not rng Is Nothing Then 'CHECK IF THE SEARCH TERM (FROM QUOTE SHEET) WAS FOUND IN THE TARGET SHEET (ESTIMATE)

    If Not rng = "" Then 'CHECK IF THE SEARCH TERM WAS A ZERO LENGTH STRING

    rng.Offset(1, 0).Select
        Range(ActiveCell, ActiveCell.Offset(14, 0)).Copy 'Copy the cell 41 rows down and 3 columns across
        'QuMa.Cells(4, i).Offset(14, 0).PasteSpecial Paste:=xlPasteValues 'Paste into the cell 14 rows below the original search term in the QUOTE sheet

        Sheets("QUOTE MASTER").Select
Range("C5000").End(xlUp).Select
ActiveCell.Offset(1, 0).Select

'Copy Formats
Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
    SkipBlanks:=False, Transpose:=True
'Copy Values
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=True

'Autofit
Columns("C:Q").EntireColumn.AutoFit

Application.CutCopyMode = False



    ElseIf rng = "" Then 'EXIT SUB IF SEARCH TERM WAS A ZERO LENGTH STRING
        'MsgBox "Work is Done"
        Exit Sub
    End If

ElseIf rng Is Nothing Then 'EXIT SUB IF SEARCH TERM WAS NOT FOUND IN THE TARGET SHEET
    'MsgBox "Work is Done"
    Exit Sub

End If

Set rng = Nothing

Next i 'Move to the next column across and loop

这是我收到错误的地方:

rng.Offset(1, 0).Select
Range(ActiveCell, ActiveCell.Offset(14, 0)).Copy

无法在循环中复制。

0 个答案:

没有答案