Sub FindAndWriteGrades()
Dim ws1 As Worksheet
Dim ws2 As Worksheet
Dim lastRow1 As Long
Dim lastRow2 As Long
Dim studentID As String
Dim grade As Variant
Dim i As Long
' 指定表一和表二的工作表对象
Set ws1 = ThisWorkbook.Worksheets("Sheet1")
Set ws2 = ThisWorkbook.Worksheets("Sheet2")
' 获取表一和表二的最后一行
lastRow1 = ws1.Cells(ws1.Rows.Count, "A").End(xlUp).Row
lastRow2 = ws2.Cells(ws2.Rows.Count, "A").End(xlUp).Row
' 遍历表一中的每一行
For i = 2 To lastRow1 ' 假设第一行为标题行,从第二行开始遍历
studentID = ws1.Cells(i, "A").Value
grade = Application.VLookup(studentID, ws2.Range("A:B"), 2, False)
If Not IsError(grade) Then
ws1.Cells(i, "C").Value = grade
End If
Next i
End Sub
Sub ReplaceTextInPath()
Dim path As String
Dim replacedPath As String
' 原始路径
path = "C:\Folder\subfolder\filexx.txt"
' 使用 Replace 函数将 "xx" 替换为固定文字
replacedPath = Replace(path, "xx", "fixed_text")
' 显示替换后的路径
MsgBox replacedPath
End Sub