J
Joanne
Hello,
I feel so frustrated with myself in not understanding values within cells
vs. the cells themselves. I am trying to total a column in a table in Word
2003. Some of the cells may be empty. The total will be put in cell E19 (at
least in this case). When some people tested the macro, we found that it is
not totaling the cells if the user placed a $ in front of the numeric value,
so I thought I should make sure that the cell's values are seen as numeric.
Here's what I did. I tried the format with both .range just alone and also
..range.text and it still gives a type mismatch.
Any help would be greatly, greatly appreciated.
Sub ConvertToCurrencyAndAdvance()
Dim i As Long, j As Long, vSum As Long
Dim oNum As Range
vSum = 0
If Not Selection.Information(wdWithInTable) Then
MsgBox "Please place the cursor inside the table & restart macro"
Exit Sub
End If
i = ActiveDocument.Tables(1).Rows.Count
For j = 9 To i
With Selection.Tables(1)
Set oNum = .Cell(i, 5).Range
oNum.End = oNum.End - 1
MsgBox oNum
.Cell(i, 5).Range.Text = FormatCurrency(Expression:=oNum, _
NumDigitsAfterDecimal:=2, IncludeLeadingDigit:=vbTrue, _
UseParensForNegativeNumbers:=vbTrue)
End With
'vSum = vSum + Val(ActiveDocument.Tables(1).Cell(Row:=i,
Column:=5).Range.Text)
MsgBox vSum
Next j
'
'myTable.Cell(i, 5).Range.InsertAfter (vSum)
End Sub
I feel so frustrated with myself in not understanding values within cells
vs. the cells themselves. I am trying to total a column in a table in Word
2003. Some of the cells may be empty. The total will be put in cell E19 (at
least in this case). When some people tested the macro, we found that it is
not totaling the cells if the user placed a $ in front of the numeric value,
so I thought I should make sure that the cell's values are seen as numeric.
Here's what I did. I tried the format with both .range just alone and also
..range.text and it still gives a type mismatch.
Any help would be greatly, greatly appreciated.
Sub ConvertToCurrencyAndAdvance()
Dim i As Long, j As Long, vSum As Long
Dim oNum As Range
vSum = 0
If Not Selection.Information(wdWithInTable) Then
MsgBox "Please place the cursor inside the table & restart macro"
Exit Sub
End If
i = ActiveDocument.Tables(1).Rows.Count
For j = 9 To i
With Selection.Tables(1)
Set oNum = .Cell(i, 5).Range
oNum.End = oNum.End - 1
MsgBox oNum
.Cell(i, 5).Range.Text = FormatCurrency(Expression:=oNum, _
NumDigitsAfterDecimal:=2, IncludeLeadingDigit:=vbTrue, _
UseParensForNegativeNumbers:=vbTrue)
End With
'vSum = vSum + Val(ActiveDocument.Tables(1).Cell(Row:=i,
Column:=5).Range.Text)
MsgBox vSum
Next j
'
'myTable.Cell(i, 5).Range.InsertAfter (vSum)
End Sub