Excel Visual Basic How To Loop Through Cells And Change Value

Do you like this?

This short example shows you a clear step by step instruction how to loop through cells and change their values in Excel Visual Basic


1) Enable Developer Mode in Excel
2) Open Tab Developer
3) Click on Visual Basic
4) Insert \ Module

Sub ChangeValue()
    Dim firstRow As Integer
    Dim lastRow As Integer
    Dim column As String
    Dim c As Range
    firstRow = 2
    lastRow = 574
    column = "G"
    For i = firstRow To lastRow
        ActiveSheet.Range(column + Trim(Str(i)), column + Trim(Str(i))).Select
        With Selection
            .Value2 = 1
        End With

End Sub

comments powered by Disqus