需要代码将数据从一张纸移动到另一张纸(VBA)

时间:2018-07-06 14:13:59

标签: excel vba excel-vba

我基本上需要在VBA中将数据从一张纸移动到另一张纸。我在照片上附带了一个示例,该示例包含要移动的数据的表(Sheet1)以及目标表(Sheet2)。我需要代码来读取第一行,并在PP列下发布PP,在生产日期列下发布日期,在名称列下发布员工姓名,在任务ID列下进行活动(擦拭,清洁,擦洗,擦拭) ,以及“多少?”下完成的活动数柱。我在所附照片的“ sheet2”中手动写了几行,但是如果我可以自动执行该过程,将会使我的生活变得更加轻松。如果我的解释不清楚,请随时与我联系并提出问题:)

来源: Pic of source sheet/data

目的地: destination sheet

1 个答案:

答案 0 :(得分:1)

如果您共享一些代码或尝试一下,那将是很棒的...这是您可以使用的一些代码,希望对您有所帮助(我假设sheet1从A列开始...因为我们看不到屏幕截图上的列标题):

Sub Macro1()

Dim wb As Workbook
Dim wsSource, wsDestination As Worksheet
Dim i, LastRowS, LastRowD As Long

Set wb = ThisWorkbook.Name
wsSource = wb.Sheets("Hoja1")
wsDestination = wb.Sheets("Hoja2")

LastRowS = wsSource.Cells(Rows.count, 1).End(xlUp).Row

EmployeeName = wsSource.Cells(3, 3).Value

t = 7

Do Until t = LastRowS

    For i = 5 To 8

    LastRowD = wsDestination.Cells(Rows.count, 2).End(xlUp).Row

        If wsSource.Cells(t, j).Value > 0 Then

        wsDestination.Cells(LastRowD + 1, 2).Value = EmployeeName
        wsDestination.Cells(LastRowD + 1, 3).Value = wsSource.Cells(t, 1).Value
        wsDestination.Cells(LastRowD + 1, 4).Value = wsSource.Cells(t, 2).Value
        wsDestination.Cells(LastRowD + 1, 5).Value = wsSource.Cells(6, j).Value
        wsDestination.Cells(LastRowD + 1, 7).Value = wsSource.Cells(t, j).Value

        End If

    Next

t = t + 1

Loop

End Sub
相关问题