基于同一行中的数据的范围的VBA列选择

时间:2018-02-19 17:35:59

标签: excel-vba vba excel

在VBA中,如何根据同一行中另一列的单元格中的值识别粘贴范围中的列起始位置?

1 个答案:

答案 0 :(得分:-1)

很抱歉,我真的不明白你想做什么,我的宏会在你找到RngB中的值时粘贴复制的单元格,使用你需要复制的宏然后执行宏。

Sub AKsooner()
Dim RngA As Range, RngB As Range
Dim Cel As Range
' You can change RngA and RngB to the columns you like
Set RngA = ActiveSheet.Columns("A")
Set RngB = ActiveSheet.Columns("B")

' also this if condition is for copy only u can add "or xlcut" to it too
If Application.CutCopyMode = xlCopy Then
   For Each Cel In RngB.Cells
       If Not Cel.Value = 0 Then
          Cells(Cel.Row, RngA.Column).PasteSpecial xlPasteAll
          Exit For
       End If
   Next Cel
End If

End Sub