本文介绍了将数据从一张纸复制到另一张纸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我尝试使用下面的代码来帮助我将一种条件下的数据从一张纸复制到另一张纸上(仅复制已完成-任命/完成-提名很成功"(范围(AB))的行).我看不到当我按下按钮时,一切.

Hello i tried this following code to help me copying data from one sheet to another with one condition (copy only the lines with "Completed - Appointment made / Complété - Nomination faite" (Range(AB)).I can not see anything when i press on the button.

欢迎任何帮助

Sub copier()
Dim ws1 As Worksheet, ws2 As Worksheet, src As Range, dest As Range, i As Integer

Set ws1 = Worksheets("Workload - Charge de travail")
Set ws2 = Worksheets("Sheet1")


For i = 2 To ws1.Range("A1").SpecialCells(xlLastCell).Row


    Set src = ws1.Range("A2:AL50") ' la selection des plages de donnees
    Set dest = ws2.Range("A2:AL50")


    If src.Cells(i, 31).Value = "Completed - Appointment made / Complété - Nomination faite" Then

       '(i,31) for my drop down list


       src.Copy Destination:=dest ' page source
       dest.Value = dest.Value 'destination page

  End If

Next i
End Sub

推荐答案

将其发布为答案,因为我认为它应该是一个.

Posting as an answer because I feel it should be one.

要继续从注释中进行讨论,您将尝试仅复制第28列中包含已完成-任命完成/已完成-提名完成"值的行.

To continue our discussion from the comments, you are trying to copy only the rows that contain the value "Completed - Appointment made / Complété - Nomination faite" in Column 28.

我认为您可以这样做:

Sub copier()
    Dim ws1 As Worksheet, ws2 As Worksheet, src As Range, dest As Range, i As Integer
    Dim DestinationRow As Integer

    DestinationRow = 1
    Set ws1 = Worksheets("Workload - Charge de travail")
    Set ws2 = Worksheets("Sheet1")

    For i = 2 To ws1.Range("A1").SpecialCells(xlLastCell).Row
        Set src = ws1.Range("A2:AL50")
        Set dest = ws2.Range("A2:AL50")

        If src.Cells(i, 28).Value = "Completed - Appointment made / Complété - Nomination faite" Then
            src.Rows(i).Copy Destination:=dest.Rows(DestinationRow)
            DestinationRow = DestinationRow + 1
        End If
    Next i
End Sub

这篇关于将数据从一张纸复制到另一张纸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 19:25