如果某行包含某个值,则将该行从一张工作表复制到另一张工作表 [英] Copy a row from one sheet to another sheet if the row contains a certain value

查看:79
本文介绍了如果某行包含某个值,则将该行从一张工作表复制到另一张工作表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这不应该是复杂的代码,但是我是Excel VBA的新手。我尝试了许多不同的方法,这些方法会导致错误,无限循环和错误的选择。

This shouldn't be complicated code, but I am new to Excel VBA. I've tried many different methods resulting in bugs, infinite loops, and wrong selections.

我需要逐行浏览 Sheet1,一次选择一行,请检查J列中的值是否正确(值= 131125),如果正确然后将其复制-将行粘贴到 Sheet2(与Sheet1中的行相同)。

I need to go row by row through "Sheet1" selecting one row at a time, check if the value in Column J is correct (value = 131125), if it is then copy - paste the row to "Sheet2" (into the same row as it was in Sheet1).

非常感谢帮助! :)

推荐答案

Sub Test()
For Each Cell In Sheets(1).Range("J:J")
    If Cell.Value = "131125" Then
        matchRow = Cell.Row
        Rows(matchRow & ":" & matchRow).Select
        Selection.Copy

        Sheets("Sheet2").Select
        ActiveSheet.Rows(matchRow).Select
        ActiveSheet.Paste
        Sheets("Sheet1").Select
    End If
Next
End Sub

这篇关于如果某行包含某个值,则将该行从一张工作表复制到另一张工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆