遍历Excel VBA或VSTO 2005中的所有单元格 [英] Iterating through all the cells in Excel VBA or VSTO 2005
问题描述
我只需要简单浏览一下Excel电子表格中的所有单元格并检查单元格中的值即可.单元格可以包含文本,数字或为空白.我对范围"的概念不是很熟悉/不适应.因此,将非常感谢任何示例代码. (我确实尝试过搜索它,但是我发现的代码片段并未完全满足我的需要)
I need to simply go through all the cells in a Excel Spreadsheet and check the values in the cells. The cells may contain text, numbers or be blank. I am not very familiar / comfortable working with the concept of 'Range'. Therefore, any sample codes would be greatly appreciated. (I did try to google it, but the code snippets I found didn't quite do what I needed)
谢谢.
推荐答案
Sub CheckValues1()
Dim rwIndex As Integer
Dim colIndex As Integer
For rwIndex = 1 To 10
For colIndex = 1 To 5
If Cells(rwIndex, colIndex).Value <> 0 Then _
Cells(rwIndex, colIndex).Value = 0
Next colIndex
Next rwIndex
End Sub
在 http://www上找到了此代码段. java2s.com/Code/VBA-Excel-Access-Word/Excel/Checksvaluesinarange10rowsby5columns.htm 它似乎非常有用,它是一种说明以有序方式检查单元格中值的方法.
Found this snippet on http://www.java2s.com/Code/VBA-Excel-Access-Word/Excel/Checksvaluesinarange10rowsby5columns.htm It seems to be quite useful as a function to illustrate the means to check values in cells in an ordered fashion.
只需将其想象为二维数组,然后应用相同的逻辑遍历单元格即可.
Just imagine it as being a 2d Array of sorts and apply the same logic to loop through cells.
这篇关于遍历Excel VBA或VSTO 2005中的所有单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!