1

我知道有一种方法可以使这段代码简短而快速,但似乎我太菜鸟了,无法实现它。我有一些合并的单元格(这是一种应该是“标准”的表格,但用户一直在弄乱它,我使用的宏会给出大量错误并且不会收集信息)。到目前为止,我所做的是制作另一段代码,再次打开“标准”表单并填写用户表单中的所有数据。

它就像一个魅力,但现在我厌倦了四处寻找和询问,因为我不知道如何简化它(我知道这对你来说一定很傻,但我不能接受它不能完成的事实 - 也我不能接受“功能强大”的 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

提前感谢您抽出时间来帮助我!

4

2 回答 2

0

做一个

`sheet("Where i want to paste").range("xxx").value=sheet("Data im copiing").range("yyy").value`

例如,您的第一个副本是:

Sheets("不知道名字").range("E9").value=Sheets("Formulaire - Form").Range("E9").value

于 2013-03-20T09:19:01.850 回答
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

ETC

顺便说一句,这是一个很好的速记

wsF.[E9] = wsU.[E9]
于 2013-03-20T09:19:16.140 回答