Alwyn Miranda
Alwyn Miranda

Reputation: 370

Adding two colours to a single cell in excel

Is it possible to fill two colors in a single cell?

(for ex: half of A1 cell with red and other half of A11 cell with green color)

Upvotes: 0

Views: 22329

Answers (4)

Ethan F.
Ethan F.

Reputation: 11

Edited the above code to be callable within the main:

Sub Duo_Col(R As Range, lngColor1, lngColor2)
Dim objColorStop As ColorStop

  With R
    'creates the gradient in cell A1
    .Interior.Pattern = xlPatternLinearGradient

    'changes its orientation, comment out if not needed
    .Interior.Gradient.Degree = 90
    
    'clears the previous colostop objects
    .Interior.Gradient.ColorStops.Clear

    'creates a colorstop object with the position 0
    Set objColorStop = .Interior.Gradient.ColorStops.Add(0)

    'changes its color to designated
    objColorStop.Color = lngColor1

    'creates a colorstop object with the position 1
    Set objColorStop = .Interior.Gradient.ColorStops.Add(1)

    'changes its color to designated
    objColorStop.Color = lngColor2

  End With

End Sub

Upvotes: 0

zi2000
zi2000

Reputation: 11

some answers below suggest gradient fills, but these don't do a clear cut between two colours.

after working with the "clear cut" problem I found this solution how to "cut" the color in gradients

example:

.Gradient.ColorStops.Add(0)   .color = color1
.Gradient.ColorStops.Add(0.5) .color = color1
.Gradient.ColorStops.Add(0.51) .color = color2
.Gradient.ColorStops.Add(1)    .color = color2

this will show color1 in the first half of the cell, and color2 in the second half

of course you can do the "cut line" where you need it e.g. position 0.3 | 0.31

Upvotes: 1

Dane I
Dane I

Reputation: 742

Use Colour Gradients, the coding below is taken from this website, it will hopefully be of assistance:

http://software-solutions-online.com/2014/04/09/excel-vba-gradients-colors/

Sub Example1_a()
Dim objColorStop As ColorStop
Dim lngColor1 As Long

'creates the gradient in cell A1 
Range("A1").Interior.Pattern = xlPatternLinearGradient
'changes its orientation 
Range("A1").Interior.Gradient.Degree = 90
'gets the color code for the second colorstop object 
lngColor1 = Range("A1").Interior.Gradient.ColorStops(2).Color
'clears the previous colostop objects 
Range("A1").Interior.Gradient.ColorStops.Clear
'creates a colorstop object with the position 0 
Set objColorStop = Range("A1").Interior.Gradient.ColorStops.Add(0)
'changes its color to green 
objColorStop.Color = vbGreen
'creates a colorstop object with the position 1 
Set objColorStop = Range("A1").Interior.Gradient.ColorStops.Add(1)
'changes its color to red 
objColorStop.Color = lngColor1
End Sub 

Upvotes: 1

Hebrus
Hebrus

Reputation: 133

This schould be possible using

Format Cell > Fill Tab > Fill Effects

select

Two Colors (choose your colors)

Upvotes: 2

Related Questions