Reputation: 953
I'm trying to color excel cells based on Male/Female genre. I was comparing the cell value to know which style i have to apply when Excel thrown this exception:
The "Values" member could not be found in the "Range" type
on this line: If wSheet.Cells(rowIndex, MFindex).Values = "MALE" Then
This is what I've tried:
For Each dr In dt.Rows
rowIndex += 1
If wSheet.Cells(rowIndex, mfIndex).Values = "MALE" Then
wSheet.Range(range).Style = "Male"
ElseIf wSheet.Cells(rowIndex, mfIndex).Values = "FEMALE" Then
wSheet.Range(range).Style = "Female"
End If
Next
A few lines earlier I did this and it works fine:
If wSheet.Cells(rowIndex, 1).Value = wSheet.Cells(rowIndex + 1, 1).Value Then
Var range
contains the range of the line (it's a simplification, don't ask about it. It has nothing to do with the exception.)
I also tell you that mfIndex
is the column index of Male/Female cells
I created my Excel sheet from my dt as DataTable
so they have the same number of rows and columns.
I checked rowIndex
and mfIndex
and their values are rowIndex = 1
, mfIndex = 26
I'm using Visual Studio 2008 and working on an .xlsx
file
Why is Excel throwing an exception? What did I do wrong?
Upvotes: 0
Views: 928
Reputation: 34045
You need to use:
If wSheet.Cells(rowIndex, MFindex).Value = "MALE" Then
Note that it is Value
and not Values
. :)
Upvotes: 1