用于查找值的 VBA

问题描述 投票:0回答:1

早上好, 我需要查找工作表 1 的 J 和 K 列中的值,看看该行中的任一列是否为 <3.5. If they are, I need to Copy that line to a sheet. This would repeat for each line on a spreadsheet. Then on Sheet 2 find the same starting mile marker in Column C and copy the next 10 lines below the condition found on sheet 1.

即:

  • 第1页enter image description here
  • 第2页enter image description here
  • 第3页enter image description here

在这种情况下,我希望看到以下内容

  • 工作表第 1 行第 2 列 J 是 <3.5. Certain cells from Row 2 would be copied to sheet 3 starting on column A
  • 工作表 2 行 2 列 C 与工作表 1 中的行 2 列 C 匹配。第 3-11 行将被复制到工作表 3 上,从 M 列开始。我还显示了 R1 的另一个实例......

表 3 将列出所有找到的实例,而无需跳行

excel vba match copy-paste findall
1个回答
0
投票

这将解决第一个要求:

Sub test()

Dim row As Long
Dim sht As Worksheet
Dim sht2 As Worksheet
Dim LastRow As Long
Dim sheet2Row As Long


Set sht = Worksheets("Sheet1")
Set sht2 = Worksheets("Sheet2")
LastRow = ActiveSheet.Cells(ActiveSheet.Rows.Count, "J").End(xlUp).row
sheet2Row = 1

For row = 2 To LastRow
    If sht.Cells(row, 10) > 3.5 Or sht.Cells(row, 10) > 3.5 Then
        sht.Range(row & ":" & row).Copy sht2.Range(sheet2Row & ":" & sheet2Row)
        sheet2Row = sheet2Row + 1
    End If

Next row


End Sub

但是,我不明白您问题的第二部分“然后在第 2 页上,在 C 列中找到相同的起始英里标记,并复制第 1 页上找到的条件下方的接下来 10 行。”

© www.soinside.com 2019 - 2024. All rights reserved.