Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
编辑Excel宏VBA使其填充到C列和右侧,而不是A列_Excel_Vba_Edit - Fatal编程技术网

编辑Excel宏VBA使其填充到C列和右侧,而不是A列

编辑Excel宏VBA使其填充到C列和右侧,而不是A列,excel,vba,edit,Excel,Vba,Edit,我目前正在使用下面的excel宏将数据从一个工作表移动到另一个工作表。设置为从第2行向下填充,只要行为空。我不希望它已经包含第2列和第3列中的数据。我尝试了很多东西,但运气不太好。我不熟悉这一点,也不熟悉“修复”其他人的宏 Sub MergeSheets() Sheets("New").Activate LastRowNew = Application.WorksheetFunction.CountA(Columns(1)) For i = 2 To LastRowNew OrderN

我目前正在使用下面的excel宏将数据从一个工作表移动到另一个工作表。设置为从第2行向下填充,只要行为空。我不希望它已经包含第2列和第3列中的数据。我尝试了很多东西,但运气不太好。我不熟悉这一点,也不熟悉“修复”其他人的宏

Sub MergeSheets()

Sheets("New").Activate
LastRowNew = Application.WorksheetFunction.CountA(Columns(1))
For i = 2 To LastRowNew
    OrderNumber = Cells(i, 3)
    Sheets("PRIOrders").Activate
    LastRowPRI = Application.WorksheetFunction.CountA(Columns(1))
    For j = 2 To LastRowPRI
        If Cells(j, 3) = OrderNumber Then
            Exit For
        ElseIf j = LastRowPRI Then
            Sheets("New").Rows(i).Copy Destination:=Sheets("PRIOrders").Rows(LastRowPRI + 1)
            Sheets("PRIOrders").Rows(2).Copy
            Sheets("PRIOrders").PasteSpecial xlPasteFormats
        End If
    Next
    Sheets("New").Activate
Next
Sub MergeSheets()

Dim shtNew As Worksheet, shtOrders As Worksheet
Dim rngOrder As Range, rngNewOrders As Range
Dim f As Range, lastRow As Long

    Set shtNew = ActiveWorkbook.Sheets("New")

    Set rngNewOrders = shtNew.Range(shtNew.Range("C2"), _
                       shtNew.Cells(Rows.Count, 3).End(xlUp))

    Set shtOrders = ActiveWorkbook.Sheets("PRIOrders")

    For Each rngOrder In rngNewOrders.Cells

        Set f = shtOrders.Columns(3).Find(Trim(rngOrder.Value), , xlValues, xlWhole)
        If f Is Nothing Then
            'find the last occupied row in Col B or C
            lastRow = Application.Max(shtOrders.Cells(Rows.Count, 2).End(xlUp).Row, _
                                      shtOrders.Cells(Rows.Count, 3).End(xlUp).Row)

            rngOrder.EntireRow.Copy shtOrders.Cells(lastRow + 1, 1)

        End If

    Next rngOrder

End Sub