vba12345

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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值