Formatting non-contiguous cells

  • Thread starter Thread starter Risky Dave
  • Start date Start date
R

Risky Dave

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
 
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
 
Spot on - my thanks

incre-d said:
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
 

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

Back
Top