2017-07-24 53 views
0

我有一个UserForm,我不想复制三个不同的值,并将它们放在我的新表中,并在每个值的前面加上一个解释,但它不起作用,有人能帮我理解为什么吗?如何将UserForm中的值导出到新的Excel表单中?

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 

预先感谢您!

+0

尝试使用'表( “Export”)。Range(“A1”)。Value'而不是'Export.Range..'。 – Soulfire

+0

应该总是说错误发生在哪个代码行。你应该使用'WorkSheets(“Export”)。Range(“A1 ......)'bla-bla – MacroMarc

回答

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 
0

这取决于您Sub的位置。如果它在模块中,则必须参考FORM。即:

Dim oF as UserForm1 


之后就可以引用在FORM领域:

Sheets("Export").Range("B1").Value = oF.TxtRiskpremie.Value 
相关问题