You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

请求优化VBA代码:按Transaction列O值分转数据至Template对应列

VBA代码调试求助:按条件批量填充跨工作表数据

需求说明

当Transaction工作表的*O列(第15列)*值为From时,将对应行的关联数据填入Template工作表的「(from)」列;当O列值为To时,填入Template工作表的「(To)」列。我写了一段VBA代码,但不确定逻辑是否正确,希望得到技术支持实现该功能。

本人编写的VBA代码

Sheets("Transaction").Select
If Cells(lr, 17).Value = "From" Then
    Range(Cells(2, 18), Cells(lr, 18)).Select
    Selection.SpecialCells(xlCellTypeVisible).Select
    Set X = Selection
    Sheets("Template").Select
    Range("D8").Select
    X.Copy
    Selection.PasteSpecial Paste:=xlPasteValues
End If

Sheets("Transaction").Select
If Cells(lr, 17).Value = "To" Then
    Range(Cells(2, 18), Cells(lr, 18)).Select
    Selection.SpecialCells(xlCellTypeVisible).Select
    Set X = Selection
    Sheets("Template").Select
    Range("F8").Select
    X.Copy
    Selection.PasteSpecial Paste:=xlPasteValues
End If

相关截图

  • Transaction工作表数据展示截图
  • Template工作表目标列位置截图

内容的提问来源于stack exchange,提问作者CM Choong

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.21 11:54:20