get the Formula Cells in Sheet using SpecialCells In C#

daffo

New Member
Joined
Nov 6, 2006
Messages
5
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
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.

Forum statistics

Threads
1,225,229
Messages
6,183,729
Members
453,185
Latest member
radiantclassy

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top