dimanche 31 mai 2020

How to Copy the fill pattern of a cell to a shape?

I have been writing a code that is copying the color of the cell and pasting it to the relevant shape. I am able to copy the color. However, it seems more complicated to copy the fill pattern of the cell. The problem i have faced is that the pattern parameter of a cell is, for example, "xlLightHorizontal" and the same pattern for a shape is "msoPatternNarrowHorizontal". Both draw the same fill pattern but have different names.

How i copy the color and fill pattern of the cell:

modelText(3, 1) = Sheets("Orders").Cells(row, j + 1).Interior.Color
modelText(3, 2) = Sheets("Orders").Cells(row, j + 1).Interior.Pattern
modelText(3, 3) = Sheets("Orders").Cells(row, j + 1).Interior.PatternColor

How i assign the color and the fill pattern to the shape:

 With Selection.ShapeRange.Fill
        .ForeColor.RGB = modelText(3, 1)
        .BackColor.RGB = modelText(3, 3)
        .Patterned (msoPatternLightHorizontal)
 End With

Note that:

Cells(row, j + 1).Interior.Pattern returns xlLightHorizontal

Where

ShapeRange.Fill.Patterned does not accept xlLightHorizontal as an input parameter

Is there anyway that you know to copy the fill pattern of a cell to a shape?

Aucun commentaire:

Enregistrer un commentaire