I have this workbook with 12 sheets each for every month of the year. Combobox for month selection and a user form for data entry. User @K.Davis helped me to get this all working.
Now I've added another sheet named Profit & Loss and what now needed is that when user adds data using user form and it goes into the lets say January 2019 sheet from there some fields gets copied/transferred into the Profit & Loss sheet as well.
The code below is for CommandBox1 on user form. Thanks to @K.Davis for that. I'm not sure if anything needs to go in there or not but putting it out just in case somebody who can help needs to see the code too.
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
How do I have specific rows also entered into the Profit & Loss sheet too? Your help is appreciated. Thanks in advance.
Cheers.
If I understand correctly, you just need to add the profit-loss to the macro, like this:
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