简体   繁体   English

Excel VBA自动填充

[英]Excel VBA Autofill

I have VBA in Access that exports data to Excel into separate sheets. 我在Access中有VBA,可以将数据导出到Excel到单独的工作表中。 The data comes in unformatted so I am going to create a macro that will format it. 数据以未格式化的格式出现,因此我将创建一个将其格式化的宏。 The export is inventory data (price of an item and quantity on hand) for multiple locations. 出口是多个地点的库存数据(物品价格和现有数量)。 The autofill will be a calculation of price*quantity autofilled to the end of the data. 自动填充将自动计算价格*数量,并自动填充到数据末尾。 The locations do no have the same amount of data in their sheets; 这些地点的工作表中没有相同数量的数据; I originally tried grouping all the sheets together and just autofilling the first sheet. 我最初尝试将所有工作表分组在一起,然后自动填充第一张工作表。 This did not work. 这没有用。 Can anyone direct me to the proper way to do this using a macro or VBA? 谁能使用宏或VBA引导我找到执行此操作的正确方法?

Note: The amount of data may change when a new inventory count comes in so the code cannot reference a specific cell in each sheet as the last row. 注意:当输入新的库存盘点时,数据量可能会更改,因此代码无法将每张工作表中的特定单元格引用为最后一行。

Thanks for you help! 感谢您的帮助!

This uses column F for the products. 这将F列用于产品。 Select each sheet and run this macro: 选择每个工作表并运行此宏:

Sub dural()
    Dim i As Long, N As Long
    N = Cells(Rows.Count, "D").End(xlUp).Row
    For i = 1 To N
        Cells(i, "F") = Cells(i, "D") * Cells(i, "E")
    Next i
End Sub

For example: 例如:

在此处输入图片说明

EDIT#1: 编辑#1:

Now that dural() is working, we can call it from: 现在dural()可以正常工作了,我们可以通过以下方式调用它:

Sub MAIN()
    Dim i As Long
    For i = 3 To Sheets.Count
        Sheets(i).Activate
        Call dural
    Next i
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM