简体   繁体   English

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

[英]VBA column selection for range based on data in same row

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

Sorry i didnt really understand what you want to do, My macro will paste your copied cells when it find value in RngB, to use the macro you will need to copy something and then execute the macro.对不起,我真的不明白你想做什么,当我的宏在 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结束子

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

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