Iterating through all the cells in Excel VBA or VSTO 2005

后端 未结 9 1613
既然无缘
既然无缘 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条回答
  •  Happy的楠姐
    2020-12-03 07:47

    In Excel VBA, this function will give you the content of any cell in any worksheet.

    Function getCellContent(Byref ws As Worksheet, ByVal rowindex As Integer, ByVal colindex As Integer) as String
        getCellContent = CStr(ws.Cells(rowindex, colindex))
    End Function
    

    So if you want to check the value of cells, just put the function in a loop, give it the reference to the worksheet you want and the row index and column index of the cell. Row index and column index both start from 1, meaning that cell A1 will be ws.Cells(1,1) and so on.

提交回复
热议问题