Unable to get a specific Cell value from a Table

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



Unable to get a specific Cell value from a Table



I need to port some VBA code to a VB.Net addon, but I can't get a particular cell value from my Table.


VBA


VB.Net



I am able to change Range(2,2) to "Test" but table.Range(2, 2).ToString gives System.__ComObject as Value.


Range(2,2)


"Test"


table.Range(2, 2).ToString


System.__ComObject



This is Image of my table


Private Sub Button1_Click(sender As Object, e As RibbonControlEventArgs) _
Handles Button1.Click

Dim table As Excel.ListObject
table = Globals.wsTables.ListObjects("vehicleDefinations")
table.Range(2, 2) = "Test"

Dim file As New System.IO.StreamWriter _
("C:UsersRyzen2600xDownloadsDebug.txt", False)
file.WriteLine(table.Range(2, 2).ToString)
file.Close()

End Sub





Try changing the code to file.WriteLine(table.Range(2, 2).Value2)
– Rawrplus
Aug 10 at 8:37


file.WriteLine(table.Range(2, 2).Value2)




3 Answers
3



Don't use .Range to retrieve the value. Instead try to use



table.DataBodyRange.Cells(2, 2)



or



[MyTable].Cells(2,2)





He's using ListObject().Range property, not Application.Range, that is a perfectly valid way to reference to table data...
– Rawrplus
Aug 10 at 8:51



ListObject().Range


Application.Range





To add to that, table.DataBodyRange.Cells(2,2) (and so will the other) will result in an error, as this expression expects = for Value assignment!
– Rawrplus
Aug 10 at 8:52



table.DataBodyRange.Cells(2,2)


=





it gives me System.__ComObject as output,
– Calculator
Aug 10 at 12:52





file.WriteLine(table.DataBodyRange.Range("B1").Value) is working but i want it in (1,1) format to put it in loop
– Calculator
Aug 10 at 12:54



You're missing the .Value


.Value


file.WriteLine(table.Range(2, 2).Value.ToString)





adding .value giving me syntax error "Option Strict On disallows late binding"
– Calculator
Aug 10 at 7:21



Please reference this code:


private void ListObject_Range()

Microsoft.Office.Tools.Excel.ListObject list1 = this.Controls.AddListObject(this.Range["A1", "C4"], "list1");
MessageBox.Show("The list object contains " + list1.Range.Cells.Count.ToString() + " cells.");



More informaiton, please see



ListObject.Range Property



Help it helps you.



Thanks,
Yuki






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

Creating a leaderboard in HTML/JS