2017-06-09 39 views
0

我想用vb.net通過Excel電子表格來循環查找和替換。此外,我需要根據另一個單元格的值來查找和替換。使用VB.NET查找和替換Excel文件,基於Excell值

我已經嘗試的代碼是:

'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文件中的列「爭議」Ĵ(10)的所有值,而我會把它想只更新「爭議」改爲「我已被替換」。如果 「刪除」 的值在列I(9)

任何幫助,不勝感激

回答

0

嘗試:

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 
+0

這工作,謝謝!不知道有什麼區別,但從來沒有它的工作。謝謝。 – user3580480

+0

很高興幫助:) – ManishChristian