I am working on dumping the contents of a flexigrid to an Excel spreadsheet and I want to change the colour of some of the cells.
I have some crude code that works after a fashion:
Set xlApp = New Excel.Application
Set xlBook = xlApp.Workbooks.Add(xlWBATWorksheet)
Set xlSheet = xlBook.Worksheets.Add
For c = 0 To icols
For r = 0 To irows
FlexDatesDays.Row = r
FlexDatesDays.Col = c
strtext = FlexDatesDays.Text
If r = 0 Then
If IsDate(strtext) Then
strtext = Format(strtext, "dd-mmm-yyyy")
End If
End If
If Trim$(strtext) = "" Then strtext = "XXXX"
xlSheet.Cells((r + 1), (c + 1)) = strtext
If FlexDatesDays.CellBackColor = vbGreen Then
xlSheet.Cells((r + 1), (c + 1)).Font.Color = vbGreen
ElseIf FlexDatesDays.CellBackColor = vbRed Then
xlSheet.Cells((r + 1), (c + 1)).Font.Color = vbRed
Else
If r > 0 And c > 0 Then
xlSheet.Cells((r + 1), (c + 1)).Font.Color = vbWhite
End If
End If
Next r
Next c
The problem I have is with the line:
If Trim$(strtext) = "" Then strtext = "XXXX"
I don't really want to populate the cells with "XXX" at all.
In the flexi grid the cells are red or blue depending on various criteria but they don't contain any text just the colour shows up which is all that is wanted.
However if I try to change the colour of the Excel cell without there being any text in the cell no colour is shown.
Is it possible to change the cell colour in the spreadsheet giving the same affect if you go into the spreadsheet and select Format Cells, Patterns and then choose a colou for the cell?
I have some crude code that works after a fashion:
Set xlApp = New Excel.Application
Set xlBook = xlApp.Workbooks.Add(xlWBATWorksheet)
Set xlSheet = xlBook.Worksheets.Add
For c = 0 To icols
For r = 0 To irows
FlexDatesDays.Row = r
FlexDatesDays.Col = c
strtext = FlexDatesDays.Text
If r = 0 Then
If IsDate(strtext) Then
strtext = Format(strtext, "dd-mmm-yyyy")
End If
End If
If Trim$(strtext) = "" Then strtext = "XXXX"
xlSheet.Cells((r + 1), (c + 1)) = strtext
If FlexDatesDays.CellBackColor = vbGreen Then
xlSheet.Cells((r + 1), (c + 1)).Font.Color = vbGreen
ElseIf FlexDatesDays.CellBackColor = vbRed Then
xlSheet.Cells((r + 1), (c + 1)).Font.Color = vbRed
Else
If r > 0 And c > 0 Then
xlSheet.Cells((r + 1), (c + 1)).Font.Color = vbWhite
End If
End If
Next r
Next c
The problem I have is with the line:
If Trim$(strtext) = "" Then strtext = "XXXX"
I don't really want to populate the cells with "XXX" at all.
In the flexi grid the cells are red or blue depending on various criteria but they don't contain any text just the colour shows up which is all that is wanted.
However if I try to change the colour of the Excel cell without there being any text in the cell no colour is shown.
Is it possible to change the cell colour in the spreadsheet giving the same affect if you go into the spreadsheet and select Format Cells, Patterns and then choose a colou for the cell?