"for each...next" and adjacent cells

A

Andrew H

Hello all,

My question reflects a poor understanding of the nature of cells,
ranges, etc.

I´m working on a macro to scan a worksheet for cells that are
underlined and then adjust the merging, alignment, etc. of those
underlined cells. Right now, I´m stuck trying to identify the
left-most of a group of adjacent, underlined cells. I have a
(working) function to test whether a side of a cell is lined or not,
so what I´d like to be able to do is say:

IF cell has bottom border AND the cell to left does not have bottom
border THEN ...

I´m using the "for each ... next" to loop through the cells, and I
would like to know how to reference adjacent cells using this
technique.

The relevant part of the code is as follows:

--------------------------
Sub FindUnderlinedCells()

Dim r1 As Range
Set r1 = Worksheets(1).Range("A1:G300")

For Each c In r1

If CellTest(c, "bottom", True) And _
CellTest((Worksheets(1).Cells(c.Row, (c.Column - 1))), "bottom",
False) Then
ModifyBlanks (c)
End If
End Sub
------------------------

As you can guess, the part that doesn´t work is the first argument of
the second call of the CellTest function.

Thanks in advance for any help!
-Andrew
 

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

Top