Compare two successive address ranges

A

Amjad

I have two Address strings (Addr1, Addr2) that change
their values in a loop. How can I exit the loop when
Addr2 is one row below Addr1?

I wrote the following code but the IF statement doesn't
work as I intended !
'************************************************
With Worksheets(1).Range("F:F")
Set c = .Find("", LookIn:=xlValues) 'search for empty
cells
firstAddress = c.Address
Addr1 = "$F$2" ' just an initial address string
Addr2 = c.Address
Do
Set SourceRange = .Range(CStr(Addr1), CStr(Addr2))
If .Range(CStr(Addr2)) <> .Range(CStr
(Addr1)).Offset(1, 0) Then
Worksheets("Report").Cells(i + 1, 6).Value
= .Application.WorksheetFunction.Average(SourceRange)
End If
i = i + 1
Addr1 = Addr2
Set c = .FindNext(c)
Addr2 = c.Address
Loop While c.Address <> firstAddress 'Stop when you
start to repeat
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top