We help IT Professionals succeed at work.
Get Started

Cells - Replaciing Border Colors

607 Views
Last Modified: 2012-08-19
I have a worksheet and want to make a formatting change to a selected range.  At the moment there are three row areas that are being selected, with multiple columns.

Example:
A Range is selected, at the moment about three rows and X (from 1 to 7, it depends) columns.
The first selected row, I would want the format to be:
Fill:
With Selection.Interior
        .Pattern = xlSolid
        .PatternColorIndex = xlAutomatic
        .Color = 14540253
With Selection.Font
        .Name = "Calibri"
        .FontStyle = "Bold"
        .Size = 11
        .Color = 6304256

For the Next two rows the following needs to occur:
Range("C10:E10").Select  '(it could be ("C10:I10")
    With Selection.Interior
        .Pattern = xlPatternLinearGradient
        .Gradient.Degree = 90
        .Gradient.ColorStops.Clear
    End With
    With Selection.Interior.Gradient.ColorStops.Add(0)
        .Color = 15131874
        .TintAndShade = 0
    End With
    With Selection.Interior.Gradient.ColorStops.Add(0.5)
        .Color = 16512499
        .TintAndShade = 0
    End With
    With Selection.Interior.Gradient.ColorStops.Add(1)
        .Color = 15131874
        .TintAndShade = 0
    End With
Range (1st column and all other rows -- at the moment its only two, or rows 2&3 of selection), this example it's "C10"
   With Selection.Font
        .Name = "Calibri"
        .FontStyle = "Regular"
        .Size = 11
        .Color = 6304256
 End With
' The second column, rest of rows, or rows 2 and 3)
    Range("D10").Select          'Col D happens to be the 2nd column in the selection
    With Selection.Font
        .Name = "Calibri"
        .FontStyle = "Bold"
        .Size = 11
        .Color = 9521920
        .TintAndShade = 0
        .ThemeFont = xlThemeFontMinor
    End With
End Sub

Open in new window


The selection will be variable and the columns and / or rows won't be fixed.  How can I make this variable so that, in reality, the first row is Gray with a Dark Blue-Bold font, and the rest of the rows are gradient, as shown, with the first column font being a dark blue regular, and the second column font being a different and bolded blue.

I have some code that will work if everything is of the same type, but not one where there are different combinations of formatting.
Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2011
Awarded 2010
Commented:
This problem has been solved!
Unlock 1 Answer and 6 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE