您好我试过以下代码来帮助我将一个工作表中的数据复制到另一个工作表中(仅复制带有“已完成 - 约会/Complété - Nomination faite”(范围(AB))的行。我看不到我按下按钮时的任何事情。
欢迎任何帮助
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
答案 0 :(得分:1)
发布作为答案,因为我觉得它应该是一个。
要继续我们在评论中的讨论,您只想在第28栏中复制包含值“已完成 - 约会/Complété - Nomination faite”的行。
我认为你可以通过以下方式完成这样的事情:
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