Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / September 2007

Tip: Looking for answers? Try searching our database.

read text from a table cell

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
juan - 20 Sep 2007 23:28 GMT
Hi, I need to go through a column of a table and sum all its values.  
Something like in text controls refered as total=total+.textbox.value...how
to extract the value of a cell.

thanks
Juan Uribe
Tony Strazzeri - 21 Sep 2007 00:57 GMT
> Hi, I need to go through a column of a table and sum all its values.
> Something like in text controls refered as total=total+.textbox.value...how
> to extract the value of a cell.
>
> thanks
> Juan Uribe

Hi Juan,

If you know the table and column you can set an object reference to
simplify things.
eg

   Dim myTableColumn As Column
   Dim ThisTableNum As Single
   Dim ThisTableColumn As Single

   ThisTableNum = 2    'lets work with table 2
   ThisTableColumn = 2 'lets work with column 2

   Set myTableColumn =
ActiveDocument.Tables(ThisTableNum).Columns(ThisTableColumn)

   Dim x
   Dim thisCell As Cell
   Dim Tot
   Dim strCellText As String

   For x = 1 To myTableColumn.Cells.Count
       Set thisCell = myTableColumn.Cells(x)
       strCellText = thisCell.Range.Text

       'strip the cell marker which at the end of each cell
       strCellText = Left(strCellText, Len(strCellText) - 2)
       Tot = Tot + Val(strCellText)
   Next

Hope this helps.

Cheers
TonyS.
juan - 21 Sep 2007 14:44 GMT
Thanks Tony, perfect,
...now I am trying to find out how in VBA is to take away the comma from
strCellText with a builtin function as in VFoxPro without going char by
char...

> > Hi, I need to go through a column of a table and sum all its values.
> > Something like in text controls refered as total=total+.textbox.value...how
[quoted text clipped - 37 lines]
> Cheers
> TonyS.
Tony Strazzeri - 23 Sep 2007 01:46 GMT
Hi Juan,
Yes, that can be tricky.  You would expect that using Val would work. But as
you can see below it doesn't.

   Dim strNumberString As String 'assuming the value is a string  say in
this var
   Dim NumVal As Double  ' or Single etc
   strNumberString = "123,000.23"

   NumVal = Val(strNumberString) 'Wrong answer

   NumVal = Val(Format(strNumberString, "General Number")) 'right answer

Cheers
TonyS.

> Thanks Tony, perfect,
> ...now I am trying to find out how in VBA is to take away the comma from
[quoted text clipped - 42 lines]
> > Cheers
> > TonyS.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.