Iterating through all the cells in Excel VBA or VSTO 2005

后端 未结 9 1603
既然无缘
既然无缘 2020-12-03 07:15

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

9条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-03 07:47

    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
    

    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.

提交回复
热议问题