Hi i wanted to know how to use SpecialCells Function in C# to get all the FormulaCells in sheet. I am able to get all the Formula Cells in a WorkSheet using VBA macro. But when i try to do it in C# it gives an error which sayas Member Not Found. I am just able to get the Count of SpecialCells that contain Formaula .
In VBA i am doing lik this
Sub GetFCells()
Dim rng As Excel.Range
Dim xlSheet As Excel.Worksheet
Dim CltnFCells As Range
Dim FCell As Range
Set xlSheet = ThisWorkbook.ActiveSheet
Set rng = xlSheet.UsedRange
Set CltnFCells = rng.SpecialCells(xlCellTypeFormulas)
For Each FCell In CltnFCells
MsgBox FCell.Formula
MsgBox FCell.Address
Next
End Sub
In C# i am doing the following
{
xlSheet=(Excel.Worksheet)xlBk.Worksheets.get_Item(1);
Excel.Range rng;
rng=xlSheet.UsedRange;
Excel.Range rg;
MessageBox.Show(rng.SpecialCells(Excel.XlCellType.xlCellTypeFormulas, Missing.Value).Count.ToString());
foreach (Excel.Range Cel in rng.SpecialCells(Excel.XlCellType.xlCellTypeFormulas, Missing.Value) )
{
MessageBox.Show(Cel.Formula.ToString());
}
}
Where am i going wrong ? it works only till it gives the count and the next statement i.e the for each statement it gives an error which says "Member not found". How to loop through the collection of Special Cells in C#. If anyone has done this before please help me out..
With Regards
Daffo
In VBA i am doing lik this
Sub GetFCells()
Dim rng As Excel.Range
Dim xlSheet As Excel.Worksheet
Dim CltnFCells As Range
Dim FCell As Range
Set xlSheet = ThisWorkbook.ActiveSheet
Set rng = xlSheet.UsedRange
Set CltnFCells = rng.SpecialCells(xlCellTypeFormulas)
For Each FCell In CltnFCells
MsgBox FCell.Formula
MsgBox FCell.Address
Next
End Sub
In C# i am doing the following
{
xlSheet=(Excel.Worksheet)xlBk.Worksheets.get_Item(1);
Excel.Range rng;
rng=xlSheet.UsedRange;
Excel.Range rg;
MessageBox.Show(rng.SpecialCells(Excel.XlCellType.xlCellTypeFormulas, Missing.Value).Count.ToString());
foreach (Excel.Range Cel in rng.SpecialCells(Excel.XlCellType.xlCellTypeFormulas, Missing.Value) )
{
MessageBox.Show(Cel.Formula.ToString());
}
}
Where am i going wrong ? it works only till it gives the count and the next statement i.e the for each statement it gives an error which says "Member not found". How to loop through the collection of Special Cells in C#. If anyone has done this before please help me out..
With Regards
Daffo