|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 tangyj 于 2024-5-17 16:29 编辑
excel中有多个表,在表A中,如果A列值等于"红星1班"且B列值等于"1小组",则C列值等于“红星小学”;如果A列值等于"新民1班"且B列值等于"2小组",则C列值等于“新民小学”;如果A列值等于"火箭班",则C列值等于“县级重点小学”;如果A列值等于其他值时,C列值保持不变。以下代码运行不能通过,求各位大佬帮忙,不胜感激。
Sub UpdateCColumnValues()
Dim ws As Worksheet
Dim lastRow As Long
Dim i As Integer
' 遍历每个工作表
For Each ws In ThisWorkbook.Worksheets
' 获取每个工作表的最后一行
lastRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row
' 循环遍历每一行
For i = 1 To lastRow
If ws.Cells(i, "A").Value = "红星1班" And ws.Cells(i, "B").Value = "1小组" Then
ws.Cells(i, "C").Value = "红星小学"
ElseIf ws.Cells(i, "A").Value = "新民1班" And ws.Cells(i, "B").Value = "2小组" Then
ws.Cells(i, "C").Value = "新民小学"
ElseIf ws.Cells(i, "A").Value = "火箭班" Then
ws.Cells(i, "C").Value = "县级重点小学"
End If
Next i
Next ws
End Sub
|
|