【问题标题】:Find and Replace in Excel file using VB.NET, based on Excell value使用 VB.NET 在 Excel 文件中查找和替换,基于 Excel 值
【发布时间】:2017-11-11 22:54:10
【问题描述】:

我正在尝试使用 vb.net 循环通过 Excel 电子表格进行查找和替换。此外,我需要根据另一个单元格的值进行此查找和替换。

我试过的代码是:

    'loop through each row
    For X As Integer = 1 To 1000
        'check if the cell value matches the search string.
        If xlWorkSheet.Cells(X, 9).value = "Removed" And xlWorkSheet.Cells(X, 10).value = "Dispute" Then
            xlWorkSheet.Cells(X, 10).Replace("Dispute", "I have been replaced")
        End If
    Next

我的问题是 Excel 文件中 J (10) 列中“争议”的所有值都在更新,而我希望它只将“争议”更新为“我已被替换”。如果 "Removed" 的值在 I (9) 列中

非常感谢任何帮助

【问题讨论】:

    标签: excel vb.net replace find


    【解决方案1】:

    试试:

    If xlWorkSheet.Cells(X, 9).Value = "Removed" And xlWorkSheet.Cells(X, 10).Value = "Dispute" Then
        xlWorkSheet.Cells(X, 10).Value = "I have been replaced"
    End If
    

    【讨论】:

    • 成功了,谢谢!不知道有什么区别,但它的工作量从来没有减少过。谢谢。
    • 很高兴为您提供帮助:)
    猜你喜欢
    • 2013-03-10
    • 1970-01-01
    • 1970-01-01
    • 2019-10-23
    • 2014-02-26
    • 2013-12-17
    • 1970-01-01
    • 2017-02-05
    • 2017-01-22
    相关资源
    最近更新 更多