Excel VBA将数据传输到行和列

时间:2017-06-19 10:13:00

标签: excel vba excel-vba

所以,我有一个excel VBA的问题。我有一份输入表和报告表。 在数据表中,我有表,包括姓名,日期和计数。我需要将其转移到其他工作表。但我需要名称,每个都在新行中,并且需要相同的数据,这些数据在列中的所有名称的输入表中键入。我已经把所有东西都做了一排,但是我坚持了。 代码到目前为止:

Sub Ievades_poga()

Dim NewRow As Integer

NewRow = Worksheets("Ievade").Range("D7").Value + 1

If Worksheets("Ievade").Range("C7").Value <> 0 Then

MsgBox "Kļūda!", vbOKOnly, "123"

Exit Sub
End If

Worksheets("Lentzāģis").Cells(NewRow, 1).Value = Worksheets("Ievade").Range("B3").Value
Worksheets("Lentzāģis").Cells(NewRow, 2).Value = Worksheets("Ievade").Range("B4").Value
Worksheets("Lentzāģis").Cells(NewRow, 3).Value = Worksheets("Ievade").Range("B5").Value
Worksheets("Lentzāģis").Cells(NewRow, 4).Value = Worksheets("Ievade").Range("B6").Value
Worksheets("Lentzāģis").Cells(NewRow, 5).Value = Worksheets("Ievade").Range("B7").Value
Worksheets("Lentzāģis").Cells(NewRow, 6).Value = Worksheets("Ievade").Range("B8").Value
Worksheets("Lentzāģis").Cells(NewRow, 8).Value = Worksheets("Ievade").Range("B9").Value
Worksheets("Lentzāģis").Cells(NewRow, 9).Value = Worksheets("Ievade").Range("B10").Value
Worksheets("Lentzāģis").Cells(NewRow, 10).Value = Worksheets("Ievade").Range("B11").Value
Worksheets("Lentzāģis").Cells(NewRow, 11).Value = Worksheets("Ievade").Range("B12").Value
Worksheets("Lentzāģis").Cells(NewRow, 12).Value = Worksheets("Ievade").Range("B13").Value
Worksheets("Lentzāģis").Cells(NewRow, 13).Value = Worksheets("Ievade").Range("B14").Value
Worksheets("Lentzāģis").Cells(NewRow, 14).Value = Worksheets("Ievade").Range("B15").Value
Worksheets("Lentzāģis").Cells(NewRow, 15).Value = Worksheets("Ievade").Range("B16").Value
Worksheets("Lentzāģis").Cells(NewRow, 16).Value = Worksheets("Ievade").Range("B17").Value
Worksheets("Lentzāģis").Cells(NewRow, 17).Value = Worksheets("Ievade").Range("B18").Value
Worksheets("Lentzāģis").Cells(NewRow, 18).Value = Worksheets("Ievade").Range("B19").Value
Worksheets("Lentzāģis").Cells(NewRow, 19).Value = Worksheets("Ievade").Range("B20").Value
Worksheets("Lentzāģis").Cells(NewRow, 20).Value = Worksheets("Ievade").Range("B21").Value
Worksheets("Lentzāģis").Cells(NewRow, 21).Value = Worksheets("Ievade").Range("B22").Value
Worksheets("Lentzāģis").Cells(NewRow, 22).Value = Worksheets("Ievade").Range("B23").Value
Worksheets("Lentzāģis").Cells(NewRow, 23).Value = Worksheets("Ievade").Range("B24").Value
Worksheets("Lentzāģis").Cells(NewRow, 24).Value = Worksheets("Ievade").Range("B25").Value
Worksheets("Lentzāģis").Cells(NewRow, 25).Value = Worksheets("Ievade").Range("B26").Value
Worksheets("Lentzāģis").Cells(NewRow, 26).Value = Worksheets("Ievade").Range("B27").Value
Worksheets("Lentzāģis").Cells(NewRow, 27).Value = Worksheets("Ievade").Range("B28").Value
Worksheets("Lentzāģis").Cells(NewRow, 28).Value = Worksheets("Ievade").Range("B29").Value
Worksheets("Lentzāģis").Cells(NewRow, 29).Value = Worksheets("Ievade").Range("B30").Value
Worksheets("Lentzāģis").Cells(NewRow, 30).Value = Worksheets("Ievade").Range("B31").Value
Worksheets("Lentzāģis").Cells(NewRow, 31).Value = Worksheets("Ievade").Range("B32").Value
Worksheets("Lentzāģis").Cells(NewRow, 32).Value = Worksheets("Ievade").Range("B33").Value
Worksheets("Lentzāģis").Cells(NewRow, 33).Value = Worksheets("Ievade").Range("B34").Value
Worksheets("Lentzāģis").Cells(NewRow, 34).Value = Worksheets("Ievade").Range("B35").Value
Worksheets("Lentzāģis").Cells(NewRow, 35).Value = Worksheets("Ievade").Range("B36").Value
Worksheets("Lentzāģis").Cells(NewRow, 36).Value = Worksheets("Ievade").Range("B37").Value
Worksheets("Lentzāģis").Cells(NewRow, 37).Value = Worksheets("Ievade").Range("B38").Value
Worksheets("Lentzāģis").Cells(NewRow, 38).Value = Worksheets("Ievade").Range("B39").Value
Worksheets("Lentzāģis").Cells(NewRow, 39).Value = Worksheets("Ievade").Range("B40").Value


MsgBox "Dati pievienoti!", vbOKOnly, "123"

Worksheets("Ievade").Range("B3").ClearContents

Worksheets("Ievade").Range("D7").Value = NewRow

Worksheets("Ievade").Range("B3").Select
End Sub

我的输入表是这样的:

Name1   | Jhon
Name2   | Don
Name3   | Arthur
Name4   | Andrew
Date    | 19.06.2017
Number  | 435
Number  | 274
Number  | 814

报告表应如下所示:

Jhon    | 19.06.2017  | 435  | 274  | 814  |
Don     | 19.06.2017  | 435  | 274  | 814  |
Arthur  | 19.06.2017  | 435  | 274  | 814  |
Andrew  | 19.06.2017  | 435  | 274  | 814  |

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:1)

代码就像这样

Sub Ievades_poga()

Dim NewRow As Integer

NewRow = Worksheets("Ievade").Range("D7").Value + 1

If Worksheets("Ievade").Range("C7").Value <> 0 Then

MsgBox "K??da!", vbOKOnly, "123"

Exit Sub
End If

    Dim vDB
   vDB = Worksheets("Ievade").Range("B3").Resize(38)
   Worksheets("Lentzāģis").Cells(NewRow, 1).Resize(1, 38) = WorksheetFunction.Transpose(vDB)

MsgBox "Dati pievienoti!", vbOKOnly, "123"

Worksheets("Ievade").Range("B3").ClearContents

Worksheets("Ievade").Range("D7").Value = NewRow

Worksheets("Ievade").Range("B3").Select
End Sub