cell table prefix and suffix

cell table prefix and suffix

jeremye86
Advocate Advocate
2,764 Views
8 Replies
Message 1 of 9

cell table prefix and suffix

jeremye86
Advocate
Advocate

i have cell values in a table that are summed up with a formula.  How do i add a prefix and suffix to these values so they sill work with the sum formula

Sub Example_CellManipulation()

    Dim MyModelSpace As AcadModelSpace
    Set MyModelSpace = ThisDrawing.ModelSpace
    Dim pt(2) As Double
    Dim MyTable As AcadTable
    Dim cName As String
    Set MyTable = MyModelSpace.AddTable(pt, 5, 5, 0.5, 0.5)
    MyTable.SetText 3, 4, "(" & 4 & ")"
    MyTable.SetText 4, 4, "=Sum(E1:E4)"

    ZoomExtents
    
End Sub

.  I am trying this and it is not working

0 Likes
2,765 Views
8 Replies
Replies (8)
Message 2 of 9

Anonymous
Not applicable

Hello ,
Just looking at your code and comparing with Autdeskreference ,
and I don't see how this can work if pt hasn't been implemented before the set.
You need to give a point there.
😉

0 Likes
Message 3 of 9

jeremye86
Advocate
Advocate

pt is just 0,0,0 

there is no need to define pt if I want it to be 0,0,0

0 Likes
Message 4 of 9

Anonymous
Not applicable
 Set MyTable = MyModelSpace.AddTable(pt, 5, 5, 0.5, 0.5)

pt has to be an array with content. If you give nothing it doesn't work.
Even if you don't care 😉

0 Likes
Message 5 of 9

jeremye86
Advocate
Advocate

It does work if you give nothing, I just tested it.  this is besides the point.  Is there even a solution to my question?  The formula gives #### error because it cant read text values.

image.png

0 Likes
Message 6 of 9

Anonymous
Not applicable

needs some research from you here. Good luck.
It's not to difficult to define the Cells. 😉
you will find by yourself.

0 Likes
Message 7 of 9

Ed__Jobe
Mentor
Mentor

@jeremye86wrote:

It does work if you give nothing, I just tested it.  this is besides the point.  Is there even a solution to my question?  The formula gives #### error because it cant read text values.

 


This really isn't a vba question but a table cell macro question. If you can get it to work in xl using their macro functions, it should work in an acad table. Can you attach an xls with some samples of prefixed text you want to 'add'?

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 8 of 9

Ed__Jobe
Mentor
Mentor

@Ed__Jobewrote:

@jeremye86wrote:

It does work if you give nothing, I just tested it.  this is besides the point.  Is there even a solution to my question?  The formula gives #### error because it cant read text values.

 


This really isn't a vba question but a table cell macro question. If you can get it to work in xl using their macro functions, it should work in an acad table. Can you attach an xls with some samples of prefixed text you want to 'add'?


I take that back. AutCAD tables don't support very many functions. You're best to create a table in xl and link the AutoCAD table to it. Then you can use xl's functions. I wasn't able to get a function to operate over a range like the Sum() function can. I had to create a column that first extracts the digits from the text, then sum that column. See the attached xlsx.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 9 of 9

jeremye86
Advocate
Advocate

Thinks Ed, I knew about linking excel tables, didn't want this as a solution.

The AutoCAD table Sum function works well for a range of cells.   The problem is that adding a prefix to a cell value with VBA changes the value to a string and thus the sum function no longer works.  The picture below shows how to add a prefix and suffix w/o VBA and still get the sum function to work.

image.png