Iterating through all the cells in Excel VBA or VSTO 2005

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

    You can use a For Each to iterate through all the cells in a defined range.

    Public Sub IterateThroughRange()
    
    Dim wb As Workbook
    Dim ws As Worksheet
    Dim rng As Range
    Dim cell As Range
    
    Set wb = Application.Workbooks(1)
    Set ws = wb.Sheets(1)
    Set rng = ws.Range("A1", "C3")
    
    For Each cell In rng.Cells
        cell.Value = cell.Address
    Next cell
    
    End Sub
    

提交回复
热议问题