【问题标题】:VBA copy row from sheet1 to sheet2 based on keywordVBA根据关键字将行从sheet1复制到sheet2
【发布时间】:2018-04-11 09:35:24
【问题描述】:

我的代码执行我想要的操作,但它会将其复制到工作表 2 中的 A 列。如果可能,我希望它将数据从 B 列开始。

Sub EFP()
Dim keyword As String: keyword = Sheets("Results").Range("B3").Value
Dim countRows1 As Long, countRows2 As Long
countRows1 = 3 'the first row of my dataset in the Data tab
endRows1 = 500 'the last row of my dataset in the Data tab
countRows2 = 6 'the first row where I want to start writing the found rows
For j = countRows1 To endRows1
    If Sheets("Data").Range("B" & j).Value = keyword Then
        Sheets("Results").Rows(countRows2).Value = Sheets("Data").Rows(j).Value
        countRows2 = countRows2 + 1
    End If
Next j

结束子

【问题讨论】:

    标签: vba excel excel-formula


    【解决方案1】:

    如果您复制并粘贴整行,它们将始终从 A 列开始。如果您希望结果从 B 列开始,您需要一种不同的方法,例如

    Sheets("Results").Range("B" & countRows2 & ":Z" & countRows2).Value = Sheets("Data").Range("A" & j & ":Y" & j).Value
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-19
      • 2016-07-25
      • 2021-05-27
      • 2020-08-02
      • 2016-01-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多