Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.tables
Helmut Helmut is offline
external usenet poster
 
Posts: 7
Default cell number format

I have one table in a word document. In column 3 and 7 starting from row 2 I
want to change the input 10000 to 10,000.
I found the following:

Sub format()
'
Dim i As Long, mynum As Range
With ActiveDocument.Tables(1)
For i = 2 To .Rows.Count
Set mynum = .Cell(i, 3).Range
mynum.End = mynum.End - 1
.Cell(i, 3).Range = format(mynum, "#,##0")
Next i
End With

End Sub
--------------------------
It works fine for column 3, but when I change the 3 to 7 in a second sub, it
changes the values, but stops at:

Set mynum = .Cell(i, 7).Range

===========
Is there anyway I can do both columns in one macro?
what's the code?
thanks
  #2   Report Post  
Posted to microsoft.public.word.tables
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default cell number format

Dim i As Long, mynum As Range
With ActiveDocument.Tables(1)
For i = 2 To .Rows.Count
Set mynum = .Cell(i, 3).Range
mynum.End = mynum.End - 1
.Cell(i, 3).Range = format(mynum, "#,##0")
Set mynum = .Cell(i, 7).Range
mynum.End = mynum.End - 1
.Cell(i, 7).Range = format(mynum, "#,##0")
Next i
End With

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Helmut" wrote in message
...
I have one table in a word document. In column 3 and 7 starting from row 2
I
want to change the input 10000 to 10,000.
I found the following:

Sub format()
'
Dim i As Long, mynum As Range
With ActiveDocument.Tables(1)
For i = 2 To .Rows.Count
Set mynum = .Cell(i, 3).Range
mynum.End = mynum.End - 1
.Cell(i, 3).Range = format(mynum, "#,##0")
Next i
End With

End Sub
--------------------------
It works fine for column 3, but when I change the 3 to 7 in a second sub,
it
changes the values, but stops at:

Set mynum = .Cell(i, 7).Range

===========
Is there anyway I can do both columns in one macro?
what's the code?
thanks



  #3   Report Post  
Posted to microsoft.public.word.tables
Helmut Helmut is offline
external usenet poster
 
Posts: 7
Default cell number format

Hi Doug,
I get this error:
Runtime error 5941 - the requested number of the collection des not exist.

It actually executes all two columns, changing the format but then the Erro
pops up and when pressing Debug the following is highlighted:

Set mynum = .Cell(i, 7).Range

Doug, in addition, I have a SUM of the two columns and would like to
'update' the field after formatting the cells in the two columns.
what additional command do I need to 'update the field'?
thanks
Helmut

"Doug Robbins - Word MVP" wrote:

Dim i As Long, mynum As Range
With ActiveDocument.Tables(1)
For i = 2 To .Rows.Count
Set mynum = .Cell(i, 3).Range
mynum.End = mynum.End - 1
.Cell(i, 3).Range = format(mynum, "#,##0")
Set mynum = .Cell(i, 7).Range
mynum.End = mynum.End - 1
.Cell(i, 7).Range = format(mynum, "#,##0")
Next i
End With

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Helmut" wrote in message
...
I have one table in a word document. In column 3 and 7 starting from row 2
I
want to change the input 10000 to 10,000.
I found the following:

Sub format()
'
Dim i As Long, mynum As Range
With ActiveDocument.Tables(1)
For i = 2 To .Rows.Count
Set mynum = .Cell(i, 3).Range
mynum.End = mynum.End - 1
.Cell(i, 3).Range = format(mynum, "#,##0")
Next i
End With

End Sub
--------------------------
It works fine for column 3, but when I change the 3 to 7 in a second sub,
it
changes the values, but stops at:

Set mynum = .Cell(i, 7).Range

===========
Is there anyway I can do both columns in one macro?
what's the code?
thanks




  #4   Report Post  
Posted to microsoft.public.word.tables
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
Default cell number format

It works fine here. To get that format for the formula, set it in the
Insert Formula dialog.

Note that if the formula is in the last row of the able, the macro as it is
written will convert the result of the formula to text. If you don't want
that to happen, change

For i = 2 To .Rows.Count

to

For i = 2 To .Rows.Count - 1

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Helmut" wrote in message
...
Hi Doug,
I get this error:
Runtime error 5941 - the requested number of the collection des not exist.

It actually executes all two columns, changing the format but then the
Erro
pops up and when pressing Debug the following is highlighted:

Set mynum = .Cell(i, 7).Range

Doug, in addition, I have a SUM of the two columns and would like to
'update' the field after formatting the cells in the two columns.
what additional command do I need to 'update the field'?
thanks
Helmut

"Doug Robbins - Word MVP" wrote:

Dim i As Long, mynum As Range
With ActiveDocument.Tables(1)
For i = 2 To .Rows.Count
Set mynum = .Cell(i, 3).Range
mynum.End = mynum.End - 1
.Cell(i, 3).Range = format(mynum, "#,##0")
Set mynum = .Cell(i, 7).Range
mynum.End = mynum.End - 1
.Cell(i, 7).Range = format(mynum, "#,##0")
Next i
End With

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

"Helmut" wrote in message
...
I have one table in a word document. In column 3 and 7 starting from row
2
I
want to change the input 10000 to 10,000.
I found the following:

Sub format()
'
Dim i As Long, mynum As Range
With ActiveDocument.Tables(1)
For i = 2 To .Rows.Count
Set mynum = .Cell(i, 3).Range
mynum.End = mynum.End - 1
.Cell(i, 3).Range = format(mynum, "#,##0")
Next i
End With

End Sub
--------------------------
It works fine for column 3, but when I change the 3 to 7 in a second
sub,
it
changes the values, but stops at:

Set mynum = .Cell(i, 7).Range

===========
Is there anyway I can do both columns in one macro?
what's the code?
thanks






Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Change number of column in an individual cell in a table JeffH Tables 2 November 30th 06 07:37 PM
Table Cell Number Format Pat Falango New Users 1 October 13th 06 02:58 PM
how do I set up number formating in a cell of a table, ie, $1.00? Meri Tables 2 August 1st 06 12:41 PM
Format within a cell howard Tables 1 December 14th 05 12:00 PM
How do I make an automatic number small caps under Number Format? grebop Microsoft Word Help 3 October 17th 05 05:31 AM


All times are GMT +1. The time now is 04:27 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"