电子表格中的VBA UserForm标签

时间:2018-04-05 11:03:22

标签: excel vba userform

我在运行我创建的UserForm时遇到问题。我的UserForm中有5个标签,但是当我运行UserForm来获取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

End Sub

UserForm

Run and submit UserForm

Excel spreadsheet

1 个答案:

答案 0 :(得分:0)

如果您想在工作表上添加标签文字,请在此代码之前:

'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更改为标签的实际名称。

相关问题