简体   繁体   English

从A列(Sheet1)复制到B列先前数据下方的B列(Sheet2)

[英]copy from column A (Sheet1) to Column B (Sheet2) below previous data of column B

How to copy data from column A (Sheet1) to column B (Sheet2) without modifying previous data on colunm B? 如何将数据从A列(Sheet1)复制到B列(Sheet2),而又不修改列B上的先前数据? Thank you in Advance. 先感谢您。

Here's a generic answer that does not replace the cells but looks for the next empty ones. 这是一个通用答案,它不会替换单元格,而是寻找下一个空单元格。 I've tried to put comments in that will help understand it. 我试图在其中添加评论将有助于理解它。

Sub CopySheet1toSheet2()

    Dim CurrRow As Integer
    Dim CurrCol As Integer
    Dim TargetRow As Integer
    Dim TargetCol As Integer

    Dim Sheet1 As String
    Dim Sheet2 As String

    Sheet1 = "Sheet1" ' name to your source sheet name
    Sheet2 = "Sheet2" ' change to your target sheet name
    CurrRow = 1
    CurrCol = 1 ' This is column A

    TargetRow = 1
    TargetCol = 2 ' This is column B

    ' Cycle through all rows in Col A until empty field reached
    While Sheets(Sheet1).Cells(CurrRow, CurrCol) <> ""

        ' See if there's a value in column B in the same row - if so, go to the next row
        While Sheets(Sheet2).Cells(TargetRow, TargetCol) <> ""
            TargetRow = TargetRow + 1
        Wend

        ' Copy the value from the source to the target
        Sheets(Sheet2).Cells(TargetRow, TargetCol) = Sheets(Sheet1).Cells(CurrRow, CurrCol)

        ' Move to the next source and target rows
        CurrRow = CurrRow + 1
        TargetRow = TargetRow + 1

    Wend

End Sub

暂无
暂无

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

相关问题 如果匹配,我需要将Sheet1列A匹配到Sheet2列A,然后将Sheet2列B复制到Sheet1列I - I need to match Sheet1 Column A to Sheet2 Column A if they match then copy Sheet2 Column B to Sheet1 Column I 如何识别A列Sheet1中与B列中的单词匹配的单词,然后将这些行复制到Sheet2? - How to identify words in Column A Sheet1 that match words in Column B, then copy those Rows to Sheet2? 将行值从 sheet1 复制到 sheet2 列 - Copy row value from sheet1 to sheet2 column 如果工作表2具有工作表匹配列,如何将数据从一个工作表1复制到另一具有相同列的工作表2 - How to copy data from one sheet1 to another same type of sheet2 having same column if sheet 2 has sheet matching column 在我从 sheet1 复制到 sheet2 之前,在 A 行 sheet2 中定义列标题 - Define column headlines in row A sheet2, before I copy from sheet1 to sheet2 将数据从 Sheet1 复制到 Sheet2,当列中的值更改时插入行 - Copy Data From Sheet1 to Sheet2, Inserting Row When Value in Column Changes 使用数组将 Sheet1 的值复制到 Sheet2 的列尾 - Copy values of Sheet1 to End of Column of Sheet2 using Array Excel VBA宏:匹配列A和B,将重复项复制到Sheet2 - Excel VBA Macro: Match Column A and B, copy duplicates to Sheet2 将sheet1数据的列A与sheet2的列A匹配,并将所有对应的行(包括重复项)拉到sheet1 - Match column A of sheet1 data with column A of sheet2 and pull all corresponding rows to sheet1 including duplicates 搜索并将工作表中的列粘贴到工作表2 - Search and paste a column from sheet1 to sheet2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM