Windy borough
New Member
- Joined
- Nov 3, 2018
- Messages
- 35
I need help showing a cell value from excel sheet onto the UserForm1
VBA code below is in my UserForm1
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
In workbooks every month have its own sheet so that makes it 12 sheets and one extra in which some data goes automatically when UserForm1 is used. I've made a TextBox6 to display cell value from any of the active sheets in the workbook. On sheet(s) all have same headings and columns so no difference. Columns G's last row should display its value on UserForm1 and auto update itself as user enters data. For me it's difficult since I don't know any VBA. I'd appreciate it very much if somebody can help me achieve this. Your help is much appreciated. Thanks in advance for your help.
Cheers.
VBA code below is in my UserForm1
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
In workbooks every month have its own sheet so that makes it 12 sheets and one extra in which some data goes automatically when UserForm1 is used. I've made a TextBox6 to display cell value from any of the active sheets in the workbook. On sheet(s) all have same headings and columns so no difference. Columns G's last row should display its value on UserForm1 and auto update itself as user enters data. For me it's difficult since I don't know any VBA. I'd appreciate it very much if somebody can help me achieve this. Your help is much appreciated. Thanks in advance for your help.
Cheers.