Microsoft Office Tutorials and References
In Depth Information
Tables: Copying Formulas
Option explicit¶
' * * * * *¶
Private frm As frmCopyFormula¶
Private startRow As Long¶
' * * * * *¶
Sub StartCopyFormula()¶
Dim sel As Word.Selection¶
'Show the form¶
'It may already be loaded, so check¶
'and re-show if it is¶
If UserForms.Count > 0 Then¶
'Variable declaration¶
Dim f As UserForm¶
For Each f In UserForms¶
If f.Caption = "Copy Formula" Then¶
Exit For¶
End If¶
'If it's not, start a new one¶
'and fill the field code¶
Set sel = Selection¶
'Make sure the selection is in a table cell¶
'and that the cell contains a formula¶
If SelectionIsValid(sel) Then¶
startRow = sel.Rows(1).Index¶
Set frm = New frmCopyFormula¶
frm.txtFieldCode.Text = _¶
MsgBox "The selection is invalid. " & _¶
"Make sure the selection is in a cell " & _¶
"with a formula.", vbCritical + vbOKOnly¶
End If¶
End If¶
End Sub¶
' * * * * *¶
Sub CopyFormula()¶
'Variable declaration¶
Dim sel As Word.Selection¶
Dim cel As Word.Cell¶
Dim partFormula As String¶
Dim newFormula As String¶
Dim updatedFormula As String¶
Dim i As Long¶
Dim posStart As Long, posEnd As Long¶
'Get the new selection: target cells¶
Set sel = Selection¶
'Make sure it's valid: in a table¶
If sel.Information(wdWithInTable) Then¶
Search JabSto ::

Custom Search