formatted numeric value?

RaizNHell

New member
Joined
Oct 27, 2009
Messages
2
Programming Experience
Beginner
Ok, I'm writing a very basic program that pulls data from an excel spreadsheet into VB.

Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
Dim range As Excel.Range
Dim Obj As Object

xlApp = New Excel.Application
xlWorkBook = xlApp.Workbooks.Open("C:\test.xlsx")
xlWorkSheet = xlWorkBook.Worksheets("Slingers Sum")

range = xlWorkSheet.UsedRange



Obj = CType(range.Cells(2, 1), Excel.Range)
TextBox1.Clear()
TextBox1.Paste(Obj.value)

Lets say that Obj.value is actually a number 32500.

How can I get this number to display as a formatted numeric value of 32,500.

I just can't seem to make this work.
 
System.InvalidCastException was unhandled
Message=Conversion from type 'Range' to type 'Integer' is not valid.


Getting this. Similar to what I got before. Its not allowing me to convert that data to an integer so I can, round, multiply, format how its displayed numerically, etc.
 
You have to get the value from the Range object, I believe it's its Value property.
 
Back
Top