I have a problem with running the UserForm I have created. I have 5 labels in my UserForm, but when I run the UserForm to get the input for the excel spreadsheet, my labels do not show, only dates, numbers etc. that I have put into the text boxes and comboboxes. Deso anyone know the solution to this problem?
Private Sub btncalculate_Click()
txtactualprofit = txtincome - txtexpenses
End Sub
Private Sub btncancel_Click()
Unload Me
End Sub
Private Sub btnreset_Click()
Unload UserForm1
UserForm1.Show
End Sub
Private Sub btnsubmit_Click()
Dim emptyRow As Long
'Make Sheet2 active
Sheet2.Activate
'Determine emptyRow
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 2
'Transfer information
Cells(emptyRow, 1).Value = cmbmonth.Value & "/" & cmbyear.Value
Cells(emptyRow, 2).Value = txtincome.Value
Cells(emptyRow, 3).Value = txtexpenses.Value
Cells(emptyRow, 4).Value = txtactualprofit.Value
Cells(emptyRow, 5).Value = txtbudgetedprofit.Value
End Sub
Private Sub monthandyear_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
MsgBox "Month & Year"
End Sub
Private Sub sbexpenses_Change()
txtexpenses.Text = sbexpenses.Value
End Sub
Private Sub sbincome_Change()
txtincome.Text = sbincome.Value
End Sub
Private Sub txtexpenses_Change()
Dim NewVal As Double
NewVal = val(txtexpenses.Text)
If NewVal >= sbexpenses.min And _
NewVal <= sbexpenses.max Then sbexpenses.Value = NewVal
End Sub
Private Sub txtincome_Change()
Dim NewVal As Double
NewVal = val(txtincome.Text)
If NewVal >= sbincome.min And _
NewVal <= sbincome.max Then sbincome.Value = NewVal
End Sub
Private Sub UserForm_Initialize()
'Empty Income Text Box and Set the Cursor
txtincome.Value = ""
txtincome.SetFocus
'Empty all other text box fields
txtexpenses.Value = ""
txtactualprofit.Value = ""
txtbudgetedprofit.Value = ""
'Clear All Month and Year Related Fields
cmbmonth.Clear
cmbyear.Clear
'Fill Month Drop Down box - Takes Jan to Dec
With cmbmonth
.AddItem "JAN"
.AddItem "FEB"
.AddItem "MAR"
.AddItem "APR"
.AddItem "MAY"
.AddItem "JUN"
.AddItem "JUL"
.AddItem "AUG"
.AddItem "SEP"
.AddItem "OCT"
.AddItem "NOV"
.AddItem "DEC"
End With
'Fill Year Drop Down box - Takes 2010 to 2018
With cmbyear
.AddItem "2010"
.AddItem "2011"
.AddItem "2012"
.AddItem "2013"
.AddItem "2014"
.AddItem "2015"
.AddItem "2016"
.AddItem "2017"
.AddItem "2018"
End With
End Sub
If you want to have the labels text on your worksheet, before this code:
'Transfer information
Cells(emptyRow, 1).Value = cmbmonth.Value & "/" & cmbyear.Value
Cells(emptyRow, 2).Value = txtincome.Value
Cells(emptyRow, 3).Value = txtexpenses.Value
Write:
Cells(1, 1) = Label1 'Change Label1 to the actual label name
Cells(1, 2) = Label2
Cells(1, 3) = Label3
Cells(1, 4) = Label4
Cells(1, 5) = Label5
And change Label1
to the actual name of the label.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.