我知道有一种方法可以使这段代码变得简短而快速,但似乎我太过于无法实现它了。我有一些合并的单元格(它是一个它应该是“标准”的形式,但是用户一直在搞乱它,我使用的宏会产生大量的错误并且不会收集信息)。到目前为止,我设法做的是制作另一段代码,再次打开“标准”表单,并填写用户表单中的所有数据。
它就像一个魅力,但现在我厌倦了寻找和询问,因为我无法弄清楚如何简化它(我知道它一定是愚蠢的你,但我不能接受这样的事实,它不能是完成 - 我也不能接受“所有强大的”VBA必须花费很长时间才能为这么少的事情编写如此多的代码。)
Application.ScreenUpdating = False
ActiveWindow.ActivatePrevious
Workbooks.Open Filename:="...\Standard Formular.xls"
Sheets("Formulaire - Form").Select
ActiveWindow.ActivateNext
Range("E9").Copy
ActiveWindow.ActivatePrevious
Range("E9").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.ActivateNext
Range("E11").Copy
ActiveWindow.ActivatePrevious
Range("E11").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.ActivateNext
Range("E13").Copy
ActiveWindow.ActivatePrevious
Range("E13").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.ActivateNext
Range("E15").Copy
ActiveWindow.ActivatePrevious
Range("E15").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.ActivateNext
Range("E17").Copy
ActiveWindow.ActivatePrevious
Range("E17").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.ActivateNext
Range("E19").Copy
ActiveWindow.ActivatePrevious
Range("E19").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("E21").Select
ActiveCell.FormulaR1C1 = Date
ActiveWindow.ActivateNext
Range("E28").Copy
ActiveWindow.ActivatePrevious
Range("E28").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.ActivateNext
Range("E30").Copy
ActiveWindow.ActivatePrevious
Range("E30").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.ActivateNext
Range("E32").Copy
ActiveWindow.ActivatePrevious
Range("E32").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.ActivateNext
Range("E34").Copy
ActiveWindow.ActivatePrevious
Range("E34").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.ActivateNext
Range("E36").Copy
ActiveWindow.ActivatePrevious
Range("E36").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.ActivateNext
Range("E38").Copy
ActiveWindow.ActivatePrevious
Range("E38").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.ActivateNext
Range("E48").Copy
ActiveWindow.ActivatePrevious
Range("E48").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.ActivateNext
Range("E50").Copy
ActiveWindow.ActivatePrevious
Range("E50").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.ActivateNext
Range("E52").Copy
ActiveWindow.ActivatePrevious
Range("E52").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.ActivateNext
Range("E54").Copy
ActiveWindow.ActivatePrevious
Range("E54").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.ActivateNext
Range("E63").Copy
ActiveWindow.ActivatePrevious
Range("E63").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.ActivateNext
Range("G63").Copy
ActiveWindow.ActivatePrevious
Range("G63").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.ActivateNext
Range("C65").Copy
ActiveWindow.ActivatePrevious
Range("C65").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.ActivateNext
Range("D65").Copy
ActiveWindow.ActivatePrevious
Range("D65").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.ActivateNext
Range("E65").Copy
ActiveWindow.ActivatePrevious
Range("E65").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.ActivateNext
Range("F65").Copy
ActiveWindow.ActivatePrevious
Range("F65").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.ActivateNext
Range("G65").Copy
ActiveWindow.ActivatePrevious
Range("G65").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.ActivateNext
Range("E67").Copy
ActiveWindow.ActivatePrevious
Range("E67").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.ActivateNext
Range("A72").Copy
ActiveWindow.ActivatePrevious
Range("A72").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.ActivateNext
Range("G72").Copy
ActiveWindow.ActivatePrevious
Range("G72").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.ActivateNext
Range("E97").Copy
ActiveWindow.ActivatePrevious
Range("E97").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.ActivateNext
ActiveWindow.Close
Application.ScreenUpdating = True
提前感谢您抽出时间帮助我!
答案 0 :(得分:0)
做一个
`sheet("Where i want to paste").range("xxx").value=sheet("Data im copiing").range("yyy").value`
例如,您的第一个副本将是:
表格(“不知道名字”)。范围(“E9”)。value =表格(“公式 - 表格”)。范围(“E9”)。值
答案 1 :(得分:0)
将要复制的工作表存储在变量中:
wsU = Sheets("Sheet name on user form goes here")
Workbooks.Open Filename:="...\Standard Formular.xls"
wsF = Sheets("Formulaire - Form")
现在而不是在激活哪个工作表之间翻转,而不是使用复制和粘贴,因为这涉及剪辑板,当你开始尝试在另一个应用程序中复制和粘贴时,这个宏运行时可能会搞砸尝试这个:
wsF.Range("E9").value = wsU.Range("E9").value
等
btw这是一个很好的简写
wsF.[E9] = wsU.[E9]