Iterating through all the cells in Excel VBA or VSTO 2005

后端 未结 9 1614
既然无缘
既然无缘 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:52

    My VBA skills are a little rusty, but this is the general idea of what I'd do.
    The easiest way to do this would be to iterate through a loop for every column:

    public sub CellProcessing()
    on error goto errHandler
    
        dim MAX_ROW as Integer   'how many rows in the spreadsheet
        dim i as Integer
        dim cols as String
    
        for i = 1 to MAX_ROW
            'perform checks on the cell here
            'access the cell with Range("A" & i) to get cell A1 where i = 1
        next i
    
    exitHandler:
        exit sub
    errHandler:
        msgbox "Error " & err.Number & ": " & err.Description
        resume exitHandler
    end sub
    

    it seems that the color syntax highlighting doesn't like vba, but hopefully this will help somewhat (at least give you a starting point to work from).

    • Brisketeer

提交回复
热议问题