#用VBA帮我把A列=数学,且B列>60分的人员C列姓名列出来 ,结果放到G列,且标记及格
Sub ListMathStudents()
Dim ws As Worksheet
Dim lastRow As Long
Dim i As Long
Dim resultRow As Long
' 设置工作表
Set ws = ThisWorkbook.Sheets("Sheet1") ' 请根据你的工作表名称进行修改
' 获取最后一行
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
' 初始化结果行号
resultRow = 1
' 遍历数据
For i = 2 To lastRow ' 假设第一行为标题行,从第二行开始遍历
If ws.Cells(i, 1).Value = "数学" And ws.Cells(i, 2).Value > 60 Then
ws.Cells(resultRow, 7).Value = ws.Cells(i, 3).Value ' 将姓名放到G列
ws.Cells(resultRow, 8).Value = "及格" ' 在H列标记为及格
resultRow = resultRow + 1
End If
Next i
End Sub
结果: