代码之家  ›  专栏  ›  技术社区  ›  Yoona May

从其他工作簿获取值并基于列名应用前缀

  •  -1
  • Yoona May  · 技术社区  · 7 年前

    enter image description here

    谢谢你。

    1 回复  |  直到 7 年前
        1
  •  2
  •   Marcucciboy2 Scott Craner    7 年前

    这应该能奏效

    Sub AdditionDeletion()
    
        Dim ws1 As Worksheet
        Set ws1 = Workbooks("Book1").Worksheets("Compare")
    
        Dim ws2 As Worksheet
        Set ws2 = Workbooks("Book2").Worksheets("Details")
    
        Dim current As Long
        current = ws2.Range("A" & rows.count).End(xlUp).row + 1
    
        Dim i As Long
        For i = 3 To ws1.Range("B" & rows.count).End(xlUp).row
            ws2.Range("A" & current) = "Addition:" & ws1.Range("B" & i).Value2
            current = current + 1
        Next i
    
        For i = 3 To ws1.Range("A" & rows.count).End(xlUp).row
            ws2.Range("A" & current) = "Deletion:" & ws1.Range("A" & i).Value2
            current = current + 1
        Next i
    
    End Sub
    
    推荐文章