我在运行我创建的用户窗体时遇到问题。我的用户窗体中有 5 个标签,但是当我运行用户窗体以获取 excel 电子表格的输入时,我的标签不显示,只有日期、数字等我已放入文本框和组合框。 Deso有人知道这个问题的解决方案吗?
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
结束子
最佳答案
如果您想在工作表上添加标签文本,请在此代码之前:
'Transfer information
Cells(emptyRow, 1).Value = cmbmonth.Value & "/" & cmbyear.Value
Cells(emptyRow, 2).Value = txtincome.Value
Cells(emptyRow, 3).Value = txtexpenses.Value
写:
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
并更改
Label1
到标签的实际名称。
关于excel - 电子表格中的 VBA UserForm 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49670791/