Macro for a range

 dzrdw0 -
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

Registration date
Sunday June 14, 2009
Last seen
July 30, 2015
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

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.

Subscribe To Our Newsletter!

The Best of CCM in Your Inbox

Subscribe To Our Newsletter!