作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我之前的问题的后续,可以找到 here
只是为了快速回顾一下,我有这张表:
ID Age Grade
1 14 90
2 15 78
3 14 90
4 16 86
5 16 86
6 15 89
7 14 88
ID Age Grade
1 14 90
3 14 90
4 16 86
5 16 86
Sub Export()
Dim lastRowcheck As Long, n1 As Long
With Worksheets("Sheet1")
lastRowcheck = Application.Max(.Range("B" & .Rows.Count).End(xlUp).Row, _
.Range("C" & .Rows.Count).End(xlUp).Row)
For n1 = lastRowcheck To 1 Step -1
If Application.CountIfs(.Columns("B"), .Cells(n1, "B").Value2, .Columns("C"), .Cells(n1, "C").Value2) > 1 Then
Debug.Print .Cells(n1, "A") & ":" & .Cells(n1, "B") & ":" & .Cells(n1, "C")
'''export to new sheet
End If
Next n1
End With
End Sub
最佳答案
更新了您的代码以显示如何将找到的行导出到新工作表:
Sub Export()
Dim lastRowcheck As Long, n1 As Long
Dim rCopy As Range
With Worksheets("Sheet1")
lastRowcheck = Application.Max(.Range("B" & .Rows.Count).End(xlUp).Row, _
.Range("C" & .Rows.Count).End(xlUp).Row)
For n1 = lastRowcheck To 1 Step -1
If Application.CountIfs(.Columns("B"), .Cells(n1, "B").Value2, .Columns("C"), .Cells(n1, "C").Value2) > 1 Then
Debug.Print .Cells(n1, "A") & ":" & .Cells(n1, "B") & ":" & .Cells(n1, "C")
'''export to new sheet
If rCopy Is Nothing Then Set rCopy = .Rows(n1) Else Set rCopy = Union(rCopy, .Rows(n1))
End If
Next n1
End With
With Sheets("Sheet2") 'For using a sheet that already exists
'With Sheets.Add(After:=Sheets(Sheets.Count)) 'For creating a brand new sheet to use
If Not rCopy Is Nothing Then rCopy.EntireRow.Copy _
Destination:=.Cells(.Rows.Count, "A").End(xlUp).Offset(1)
End With
End Sub
关于vba - 如何将识别的值导出到新工作表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43502293/
我是一名优秀的程序员,十分优秀!