Macro for a range

Closed
dzrdw0 - Aug 22, 2010 at 07:09 PM
 dzrdw0 - Aug 24, 2010 at 10:27 PM
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 responses

venkat1926 Posts 1863 Registration date Sunday June 14, 2009 Status Contributor Last seen August 7, 2021 811
Aug 24, 2010 at 06:54 AM
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
0
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.
0