0
所以,我有一個問題與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 |
任何人都可以幫我嗎?
你應該閱讀有關[循環](https://stackoverflow.com/documentation/vba/1873/flow-control-structures)和[移調]( https://msdn.microsoft.com/VBA/Excel-VBA/articles/worksheetfunction-transpose-method-excel)。 –
我沒有看到您的數據或期望的輸出的例子。這使得很難幫助你。請編輯您的原始問題以提供[最小,完整和可驗證示例](http://stackoverflow.com/help/mcve) –
您是否可以爲每個工作表提供多個日期,如果是,那麼這些日期應該被處理?此外,你可以有多組名/日期/號碼;如果是的話,你怎麼知道哪些名字與哪些日期和哪些數字相關聯? –