Excel

您所在的位置:网站首页 excel定位整行 Excel

Excel

2023-05-30 19:07| 来源: 网络整理| 查看: 265

我发现这段Excel VBA代码非常简短干净,它可以根据条件复制整个行。我将它添加到我的vba项目中,它工作得很好,唯一的问题是它复制了整个行。

我试图实现代码,只将E列中的行复制到K列,但我没有成功地将代码调整为我想要做的事情。

基本上,在工作表"verification“中,如果列"AB”= "Final“,则将具有"Final”的行从列E复制到工作表"upload“。

我拉扯我的头发让它工作,我已经找遍了每一个人,但没有运气。我知道在这个平台上,我可以找到我的问题的解决方案。我将继续使用代码。

Sub CopyEachRowtoUpload() Application.ScreenUpdating = False Dim wsI As Worksheet, wsO As Worksheet Dim LastRow As Long, i As Long, j As Long Dim LastColumn As Long, a As Long, b As Long Dim rng As Range Set wsI = Sheets("Verification") Set wsO = Sheets("Upload") Set rng = wsI.Range("E:K") 'Last Row in a Column. Row need to start in row 2 LastRow = wsI.Cells(Rows.Count, "K").End(xlUp).Row 'Last Column in a Row. Rows from Column E to K is what I want to copy LastColumn = wsI.Cells(5, Columns.Count).End(xlToLeft).Column 'Row start j = 2 With wsI 'Loop through each row For i = 1 To LastRow If Range("AB" & i).Value = "Final" Then wsI.Rows(i).Copy wsO.Rows(j).PasteSpecial Paste:=xlPasteValues j = j + 1 End If Next i End With Application.ScreenUpdating = True End Sub


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3