ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Formatting non-contiguous cells (https://www.excelbanter.com/excel-programming/417793-formatting-non-contiguous-cells.html)

Risky Dave

Formatting non-contiguous cells
 
Hi,

I need to be able to format some cells that are not adjacent to each other.
I can do it on a cell-by cell basis:

CurrentCellNew.Select
With Selection.Interior
.ColorIndex = 15
End With
CurrentCellNew = CurrentCellNew.Offset(0, 1)
CurrentCellNew.Select
With Selection.Interior
.ColorIndex = 15
End With
CurrentCellNew = CurrentCellNew.Offset(0, 12)
CurrentCellNew.Select
With Selection.Interior
.ColorIndex = 15
End With

but this is really ugly. How do I select a number of cells (their offset
position from CurrentCellNew will always be known)?

This is in Office '07 under Vista.

TIA

Dave

incre-d[_2_]

Formatting non-contiguous cells
 

Dim allCells as range

set allCells = CurrentCellNew
set allCells = Application.Union(allCells,CurrentCellNew.Offset(0 ,1))
set allCells = Application.Union(allCells,CurrentCellNew.Offset(0 ,12))

allCells.Interior.ColorIndex

"Risky Dave" wrote:

Hi,

I need to be able to format some cells that are not adjacent to each other.
I can do it on a cell-by cell basis:

CurrentCellNew.Select
With Selection.Interior
.ColorIndex = 15
End With
CurrentCellNew = CurrentCellNew.Offset(0, 1)
CurrentCellNew.Select
With Selection.Interior
.ColorIndex = 15
End With
CurrentCellNew = CurrentCellNew.Offset(0, 12)
CurrentCellNew.Select
With Selection.Interior
.ColorIndex = 15
End With

but this is really ugly. How do I select a number of cells (their offset
position from CurrentCellNew will always be known)?

This is in Office '07 under Vista.

TIA

Dave


Risky Dave

Formatting non-contiguous cells
 
Spot on - my thanks

"incre-d" wrote:


Dim allCells as range

set allCells = CurrentCellNew
set allCells = Application.Union(allCells,CurrentCellNew.Offset(0 ,1))
set allCells = Application.Union(allCells,CurrentCellNew.Offset(0 ,12))

allCells.Interior.ColorIndex

"Risky Dave" wrote:

Hi,

I need to be able to format some cells that are not adjacent to each other.
I can do it on a cell-by cell basis:

CurrentCellNew.Select
With Selection.Interior
.ColorIndex = 15
End With
CurrentCellNew = CurrentCellNew.Offset(0, 1)
CurrentCellNew.Select
With Selection.Interior
.ColorIndex = 15
End With
CurrentCellNew = CurrentCellNew.Offset(0, 12)
CurrentCellNew.Select
With Selection.Interior
.ColorIndex = 15
End With

but this is really ugly. How do I select a number of cells (their offset
position from CurrentCellNew will always be known)?

This is in Office '07 under Vista.

TIA

Dave



All times are GMT +1. The time now is 03:36 AM.

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