Announcement

Collapse
No announcement yet.

Fill Cell in Excel

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Fill Cell in Excel

    I can change the bold and Font in Excel, but how to change the background colour of a range of cells?




    '_____________________________________________________________________________________________________________________
    FUNCTION Write_to_Excel(Koo_X AS LONG, Koo_Y AS LONG, schreibe AS VARIANT, farbe AS LONG) ' spalte zeile
    DIM vRange AS VARIANT
    DIM vVnt AS VARIANT
    DIM vVnB AS VARIANT
    DIM oExcelWorkSheet AS GLOBAL ExcelWorkSheet

    CALL Kolonne(Koo_X,Koo_Y)
    LET vRange = koordinaten
    'farbe=2
    IF farbe=0 THEN LET vVnt = RGB(0,0,0)
    IF farbe=1 THEN LET vVnt = RGB(255,0,0) ' Rot
    IF farbe=2 THEN LET vVnt = RGB(0,0,255) ' Blau
    IF farbe=3 THEN LET vVnt = RGB(0,150,0) ' Grün

    IF farbe&>0 THEN vVnB=15
    OBJECT LET oExcelWorkSheet.Range(vRange).Font.Color = vVnt
    OBJECT LET oExcelWorkSheet.Range(vRange).Font.Bold = vVnB
    OBJECT LET oExcelWorkSheet.Range(vRange).Value = schreibe
    END FUNCTION

  • #2
    Try

    Code:
    OBJECT LET oExcelWorkSheet.Range(vRange).Interior.ColorIndex  = <Color index in current palette>
    OBJECT LET oExcelWorkSheet.Range(vRange).Interior.Pattern = <Pattern constant>
    Hint: What I do if I don't know which object/property is the right one for the task: Record a little macro and look what it does. In this case, I set the background of one cell to yellow. The resulting macro:
    Code:
        With Selection.Interior
            .ColorIndex = 6
            .Pattern = xlSolid
        End With

    Comment


    • #3
      Knuth
      I have to thank you for that one to. I use the macro method but could never get that one to work, or get all the columns to automatically resize to fit the contents. I have done a lot of COM with Word but always have trouble with Excel
      John

      Comment


      • #4
        Thanks

        Thanks it works!

        Comment

        Working...
        X