rob0923
09-02-2009, 06:05 PM
Hi,
I am looking to add a range of cells in vba and not in excel. It seems easy enough but I been stuck on this for a while because it won't transfer the value to a word bookmark.
The code I have is as follows. I really don't want to set each range individually A1 + A2 + A3. I would prefer as follows. Not sure why it isn't working.
Private Function Special_Calculation(ByRef objDoc As Object) As Boolean
Dim PlanNos1, PlanNos2
With Worksheets("Sheet1")
PlanNos1 = Application.WorksheetFunction.Sum(Range("I31:J31"))
PlanNos2 = Application.WorksheetFunction.Sum(Range("I32:I42"))
End With
With objDoc.Bookmarks
.Item("PlanNos1").Range.InsertAfter (PlanNos1.Value)
.Item("PlanNos2").Range.InsertAfter (PlanNos2.Value)
End With
End Function
I have even tried PlanNos1 = Application.Sum(Range("I31:J31"))
I am looking to add a range of cells in vba and not in excel. It seems easy enough but I been stuck on this for a while because it won't transfer the value to a word bookmark.
The code I have is as follows. I really don't want to set each range individually A1 + A2 + A3. I would prefer as follows. Not sure why it isn't working.
Private Function Special_Calculation(ByRef objDoc As Object) As Boolean
Dim PlanNos1, PlanNos2
With Worksheets("Sheet1")
PlanNos1 = Application.WorksheetFunction.Sum(Range("I31:J31"))
PlanNos2 = Application.WorksheetFunction.Sum(Range("I32:I42"))
End With
With objDoc.Bookmarks
.Item("PlanNos1").Range.InsertAfter (PlanNos1.Value)
.Item("PlanNos2").Range.InsertAfter (PlanNos2.Value)
End With
End Function
I have even tried PlanNos1 = Application.Sum(Range("I31:J31"))