简体   繁体   English

使用Excel VBA宏将值从一列添加到另一列

[英]Use Excel VBA Macro to Add values from one Column to another

I need a VBA macro that adds the values in column "Unclassified" into "Corporate." 我需要一个VBA宏,它将“未分类”列中的值添加到“公司”中。

I cannot do this with a Formula because I must delete the column Unclassified completely afterwards. 我无法使用公式来执行此操作,因为之后必须完全删除未分类列。

For example: 例如:

之前

Will turn into: 会变成:

后

let me know if this works 让我知道这个是否奏效

Sub CorporateAdd()
    Application.ScreenUpdating = False

    Dim TotalRows As Long
    Dim UnclassArray As Variant, CorporateArray As Variant
    TotalRows = Range("L1048576").End(xlUp).Row

    UnclassArray = Columns("N")
    CorporateArray = Columns("L")

    For i = 4 To TotalRows
        CorporateArray(i, 1) = CorporateArray(i, 1) + UnclassArray(i, 1)
    Next i

    Columns("L") = CorporateArray

    'Uncomment this if you want it to automatically delete "Unclassified"
    'Columns("N").Delete Shift:=xlLeft

    Application.ScreenUpdating = True
End Sub

But for future reference, I don't think people like when you ask for code, try it out yourself first and if it doesn't work come here for help on fixing it! 但是,为了将来参考,我认为人们不喜欢在请求代码时先尝试一下,如果它不起作用,请寻求帮助来修复它! :) :)

暂无
暂无

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

相关问题 VBA Excel宏将一列复制到另一个工作簿中 - VBA Excel Macro Copying One Column into Another Workbook 是否可以使用VBA将宏从一个Excel工作簿复制到另一个工作簿? - Is it possible to copy a macro from one Excel workbook to another using VBA? Excel 将内容从一张纸复制到另一张纸,无需 VBA/宏 - Excel copy contents from one sheet to another without VBA/Macro Excel VBA宏,用于打开信息并将信息从一个工作簿加载到另一个工作簿 - Excel VBA Macro for opening and loading information from one workbook to another Excel-将单元格+宏+ VBA从一张纸复制到另一张纸? - Excel - copy cells+macro+VBA from one sheet to another? VBA 宏将数据从一个 excel 文件复制到另一个 - VBA macro to copy data from one excel file to another Excel VBA宏将信息从一本书导入到另一本书 - excel vba macro to import information from one book to another Excel VBA - 根据 3 个条件(复杂的 IF AND 相关 VBA 与通配符)使用另一张工作表中的值填充一张工作表上的列 - Excel VBA - Populate a column on one sheet with values from another sheet based on 3 criteria (complicated IF AND related VBA with wildcards) Excel VBA - 根据另一列中的值填充一列中的单元格 - Excel VBA - populate cells in one column based on values in another one 从一张纸到另一张纸的VBA宏复制列,中间有空白 - VBA macro copy column from one sheet to another with blanks in between
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM