使用另一个单元格的值填充单元格

我正在编写一个VBA脚本来生成帐户报告的声明。 我已经把这个报告分成了两部分:1.标题,2.第一份工作条目,3.附加工作条目和4.总和栏。 每个部分都有自己的热键捷径。 到目前为止,我只在这些部分的布局方面做过工作,现在我已经准备好了,并试图编写计算方面的问题。

我是VBA编程的新手,所以我的问题很简单。 我希望从一个细胞中获得价值。 我已经能够得到脚本来做到这一点,但它是一个string和string填充在脚本本身的写作过程中。 我想写第一个条目, 然后让用户input一个数字到一个单元格中,然后将相同的数字填充到另一个单元格中。 基本上,我希望所有的公式都能够写入,并为应收帐款人员做好准备,只需input他们需要的数字并做出决定。

这里是macros的代码,快捷键是Shift + ctrl + D。它所做的第一件事就是询问在哪里放置部分(单元格地址),然后询问需要多less条目(发票)。 macros然后打印出所需的input格式,然后循环复制并粘贴在该条目下方的用户指定的条目。 这里是:

Sub STOACre() Dim Start As Range Set Start = Application.InputBox(prompt:="What Cell Address would you like to start your invoice entries at?", Type:=8) Dim Entries As Integer Entries = InputBox(prompt:="How Many Invoices are you entering for this Project number?") 'This is the Entry portion of the page Application.Goto Start With ActiveCell.Range("A1:G1, f3").Font .Name = "Calibri" .bold = True End With ActiveCell.FormulaR1C1 = "Inv.no" ActiveCell.Offset(0, 1).Range("A1").FormulaR1C1 = "Job.no" ActiveCell.Offset(0, 2).Range("A1").FormulaR1C1 = "Due Date" ActiveCell.Offset(0, 4).Range("A1").FormulaR1C1 = "Aging(Days)" ActiveCell.Offset(0, 5).Range("A1").FormulaR1C1 = "Invoice Amount" ActiveCell.Offset(0, 6).Range("A1").FormulaR1C1 = "Due Amount" With ActiveCell.Range("A1:G1").Interior .Pattern = xlSolid .PatternColorIndex = xlAutomatic .ThemeColor = xlThemeColorAccent5 .TintAndShade = 0.799981688894314 .PatternTintAndShade = 0 End With With ActiveCell.Range("A1:G1").Borders .LineStyle = xlContinuous .Weight = xlThin End With ActiveCell.Range("A1:G1").Font.bold = True For i = 1 To Entries Application.Goto Start With ActiveCell.Offset(1, 0).Range("A1:G1").Borders .LineStyle = xlContinuous .Weight = xlThin End With With ActiveCell.Offset(1, 0).Range("A1:G1") .Copy .Insert Shift:=xlDown End With Next i ActiveCell.Offset(Entries + 1, 5).Range("A1").FormulaR1C1 = "Sub Total" With ActiveCell.Offset(Entries + 1, 0).Range("A1:E1") .MergeCells = True .FormulaR1C1 = " " End With End Sub 

感谢您和对不起打扰这样一个简单的问题。 我已经看到类似的贴子,但他们似乎没有为我的情况工作。 任何帮助和/或build议,将不胜感激。

只要使用公式,如果你想单元格A1等于放入A2的任何东西,那么这样做:

 Range("A1").Formula = "=A2" 

你想在哪里定义一个单元应该等于另一个单元的位置? 我可以帮助你更具体的代码。