NumberFormat for range where first row is null

Apr 12, 2013 at 4:46 PM
Trying to format columns of dates. Everything works great when the first row of the range has data in it. If the first row is empty/null, however, the NumberFormat applied to the range seems to get ignored. How to get around this? Thanks!
            Dim colCount, r, c As Integer
            Using dv As DataView = GetCompleteContractData()
                colCount = dv.Table.Columns.Count - 1
                For c = 0 To colCount  'for each col
                    ws.Cells(1, c + 1).Value = dv.Table.Columns(c).ColumnName.Replace("_", " ")  'write out the header
                    For r = 0 To dv.Count - 1  'for each row
                        ws.Cells(r + 2, c + 1).Value = dv(r)(c)  'write out data
                    Next
                    If dv.Table.Columns(c).DataType = GetType(Date) Then  'format date columns
                        Using drng As ExcelRange = ws.Cells(2, c, r + 1, c)
                            drng.Style.Numberformat.Format = "mm/dd/yyyy"
                        End Using
                    End If
                Next
            End Using