GSp
GSp

Reputation: 21

vsto excel 2010 add in - get value of cell when contents refer to another cell and formula

I'm trying to get the value of a cell using this: Globals.Sheet3.Cells.Range["A2"].Value2 as string; Cell A2 refers to a cell on a different sheet that in turn refers to a formula on another sheet. The code above always returns null. How can I get the text of cell a2?

Upvotes: 2

Views: 1962

Answers (1)

Anonymous Type
Anonymous Type

Reputation: 3061

If you use...

VB.Net

Dim res As String
res = ThisWorkbook.Worksheets("Sheet3").Range("A2").Value2.ToString()

C#

String res = "";
res = ThisWorkbook.Worksheets["Sheet3"].Range("A2").Value2.ToString()

Does that work?

It's not clear from the question if the problem is with a section of VB.Net or C# code, however I'd say the problem is either with the way your a using the Range method, or possibly with your use of the Globals object.

UPATE to QUESTION: Based on feedback from the questioner, the ANSWER to this question is to use code such as... C#

String res = "";
res = ThisWorkbook.Worksheets["Sheet3"].Range("A2").Text

Upvotes: 1

Related Questions