如何将特定行数据传输到同一工作簿中的另一个 sheet?

How to transfer specific row data on to another sheet in same workbook?

我有这本工作簿,一年中每个月都有 12 sheets。用于月份选择的组合框和用于数据输入的用户表单。用户@K.Davis 帮助我完成了所有工作。

现在我添加了另一个 sheet 名为 Profit & Loss,现在需要的是当用户使用用户表单添加数据时,它会从那里进入假设 2019 年 1 月 sheet字段也会 copied/transferred 进入损益 sheet。

以下代码适用于用户窗体上的 CommandBox1。感谢@K.Davis。我不确定是否需要将任何内容放入其中,但将它放出来以防万一可以提供帮助的人也需要查看代码。

Private Sub UserForm_Initialize()
 Dim i As Long
 For i = 1 To ThisWorkbook.Sheets.Count
     Me.ComboBox1.AddItem ThisWorkbook.Sheets(i).Name
   Next
End Sub

Private Sub CommandButton1_Click()

 Dim dcc As Long
 Dim abc As Worksheet

 Set abc = ThisWorkbook.Worksheets(Me.ComboBox1.Value)

 With abc

    dcc = .Range("A" & Rows.Count).End(xlUp).Row

    .Cells(dcc + 1, 1).Value = Date
    .Cells(dcc + 1, 2).Value = Me.TextBox1.Value
    .Cells(dcc + 1, 3).Value = Me.TextBox2.Value
    .Cells(dcc + 1, 4).Value = Me.TextBox3.Value
    .Cells(dcc + 1, 5).Value = Me.TextBox4.Value
    .Cells(dcc + 1, 6).Value = Me.TextBox5.Value

End With
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""

End Sub

如何将特定行也输入到损益 sheet 中?感谢您的帮助。提前致谢。

干杯。

如果我没理解错的话,你只需要在宏中加上盈亏就可以了,像这样:

Private Sub UserForm_Initialize()
Dim i As Long
For i = 1 To ThisWorkbook.Sheets.Count
    Me.ComboBox1.AddItem ThisWorkbook.Sheets(i).Name
  Next
End Sub

Private Sub CommandButton1_Click()

 Dim dcc As Long
 Dim abc As Worksheet, pfl As Worksheet

 Set abc = ThisWorkbook.Worksheets(Me.ComboBox1.Value)
 Set pfl = Sheets("ProfitLoss")

With abc

   dcc = .Range("A" & Rows.Count).End(xlUp).Row

.Cells(dcc + 1, 1).Value = Date
.Cells(dcc + 1, 2).Value = Me.TextBox1.Value
.Cells(dcc + 1, 3).Value = Me.TextBox2.Value
.Cells(dcc + 1, 4).Value = Me.TextBox3.Value
.Cells(dcc + 1, 5).Value = Me.TextBox4.Value
.Cells(dcc + 1, 6).Value = Me.TextBox5.Value

End With

With pfl
dcc = .Range("A" & Rows.Count).End(xlUp).Row

.Cells(dcc + 1, 1).Value = Date
.Cells(dcc + 1, 2).Value = Me.TextBox1.Value
.Cells(dcc + 1, 3).Value = Me.TextBox2.Value
.Cells(dcc + 1, 4).Value = Me.TextBox3.Value
.Cells(dcc + 1, 5).Value = Me.TextBox4.Value
.Cells(dcc + 1, 6).Value = Me.TextBox5.Value
end with

TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""

End Sub