如何将值从UserForm导出到新的Excel表?

时间:2017-07-24 13:59:23

标签: excel vba

我有一个UserForm,我不想复制三个不同的值并将它们放在我的新表中,并在每个值前面加上解释,但它不起作用,有人可以帮我理解为什么吗? / p>

Private Sub cmbExport_Click()

Sheets.Add(After:=Sheets(Sheets.Count)).Name = "Export"

Export.Range("A1").Value = "Riskpremie"
Export.Range("A2").Value = "Teknisk premie"
Export.Range("A3").Value = "Slutpremie"

Export.Range("B1").Value = TxtRiskpremie.Value
Export.Range("B2").Value = TxtTeknpremie.Value
Export.Range("B3").Value = txtSlutpremie.Value

End Sub

提前谢谢!

2 个答案:

答案 0 :(得分:0)

这取决于你Sub的位置。如果它在模块中,则必须引用FORM。即:

Dim oF as UserForm1


然后,您可以参考FORM

中的字段
Sheets("Export").Range("B1").Value = oF.TxtRiskpremie.Value

答案 1 :(得分:0)

我们的Export未定义,因此不起作用:

Private Sub cmbExport_Click()
Dim Export as wWorksheet
Set Export = Sheets.Add(After:=Sheets(Sheets.Count))
Export.Name = "Export"

Export.Range("A1").Value = "Riskpremie"
Export.Range("A2").Value = "Teknisk premie"
Export.Range("A3").Value = "Slutpremie"

Export.Range("B1").Value = TxtRiskpremie.Value
Export.Range("B2").Value = TxtTeknpremie.Value
Export.Range("B3").Value = txtSlutpremie.Value

End Sub
相关问题