ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   "for each...next" and adjacent cells (https://www.excelbanter.com/excel-programming/277897-each-next-adjacent-cells.html)

Andrew H[_2_]

"for each...next" and adjacent cells
 
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


All times are GMT +1. The time now is 02:29 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com