2016-08-24 298 views
0

我在Excel和vba中的知識接近於零。 我試圖做到以下幾點:Excel VBA - 查找具有特定值的所有行並獲取其行數

for each row in ActiveSheet.ListObjects("SheetPotatoData") 
    if cell (column 5):(row) value equals "potato" 
     do something with (column 2):(row) 

我真的很感激,如果你能見識一下正確的語法來做到這一點。

非常感謝!

+0

https://www.google.co.uk/search?q=get+range+value+vba&sourceid=ie7&rls=com.microsoft:en-GB:IE-地址&ie =&oe =&safe = active&gfe_rd = cr&ei = 3Ia9V8XpKZDCaPvoj6gC&gws_rd = ssl –

回答

3

看看這裏:http://www.excel-easy.com/vba/range-object.html

For i = 1 To ActiveSheet.ListObjects("TableNameHere").ListRows.Count 
    If Cells(i,5).Value = "potato" Then 
     Cells(i,2).Value = "New value" 
    End If 
Next 
+0

感謝您不給我一個鏈接到谷歌搜索:)這正是我一直在尋找的!我簡單地用ActiveSheet.ListObjects(「TableNameHere」)。ListRows.Count替換了50,現在它在整個表上循環。 – Sinros

+0

使用ActiveSheet.ListObjects(「TableNameHere」)更新答案。ListRows.Count' –

相關問題