Macro for a range

Closed
Report
-
 dzrdw0 -
Hello,
I have this macro below that works only on single cell. How can I change the coding from just singl cell to a range of cell (a1:a30). Thanks.


Sub test()
With Range("A1")
If .Address(False, False) = "A1" Then
If IsNumeric(.Value) Then
Application.EnableEvents = False
Range("B1").Value = Range("B1").Value + .Value
Application.EnableEvents = True
End If
End If
End With
End Sub




2 replies

Posts
1864
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
803
it is not clear why this code statement

If .Address(False, False) = c.Address Then


I shall rather than have the macro like this see whether this solves your problem


Sub test()
Dim r As Range, c As Range
Set r = Range("A1:A30")
For Each c In r
With c
'If .Address(False, False) = c.Address Then
'If IsNumeric(.Value) Then
If IsNumeric(c) Then
Application.EnableEvents = False
c.Offset(0, 1).Value = c.Offset(0, 1).Value + .Value
Application.EnableEvents = True
End If

End With
Next c
End Sub
venkat1926

Thanks. that's what i've been looking. it works out great.
"If .Address(False, False) = c.Address Then" means if any of the cell is empty then it goes to the next one, i think.