Userform - Option Buttons

  • Thread starter JinkyJulie via OfficeKB.com
  • Start date
J

JinkyJulie via OfficeKB.com

Hi again all...

I have a userform, code is below... I want to make the choice and perform the
typing in the cells... (/70, etc...) along with the text replacement...

The text replacement works brilliantly but the typing into the cells does not
occur... I've played with it, researched and played some more... no good...
It's got to be something simple to give me this much grief...

Any direction would be very appreciated... (note: I know that looping through
the cells would be better... haven't gotten that far yet...)

As always, thanks for your time to help me learn Word VBA...

Regards,

Julie


Private Sub cmdOK_Click()
Dim strFruit As String
Dim i As Integer

If optFruitOne = True Then strFruit = "Banana "

ActiveDocument.Tables(4).Cell(2, 2).Select
Selection.TypeText Text:="/70"
ActiveDocument.Tables(7).Cell(2, 2).Select
Selection.TypeText Text:="/70"
ActiveDocument.Tables(10).Cell(2, 2).Select
Selection.TypeText Text:="/70"
ActiveDocument.Tables(13).Cell(2, 2).Select
Selection.TypeText Text:="/70"
End If

If optFruitTwo = True Then strFruit = "Apple "

ActiveDocument.Tables(4).Cell(2, 2).Select
Selection.TypeText Text:="/64"
ActiveDocument.Tables(7).Cell(2, 2).Select
Selection.TypeText Text:="/64"
ActiveDocument.Tables(10).Cell(2, 2).Select
Selection.TypeText Text:="/64"
ActiveDocument.Tables(13).Cell(2, 2).Select
Selection.TypeText Text:="/64"
End If

If optFruitThree = True Then strFruit = "Orange "
ActiveDocument.Tables(4).Cell(2, 2).Select
Selection.TypeText Text:="/83"
ActiveDocument.Tables(7).Cell(2, 2).Select
Selection.TypeText Text:="/83"
ActiveDocument.Tables(10).Cell(2, 2).Select
Selection.TypeText Text:="/83"
ActiveDocument.Tables(13).Cell(2, 2).Select
Selection.TypeText Text:="/83"
End If

Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = strPatrol
.Replacement.Text = ""
.Forward = True
End With
Selection.Find.Execute

Application.ScreenUpdating = False
For i = 1 To 8
With Selection
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseStart
Else
.Collapse Direction:=wdCollapseEnd
End If
.Find.Execute Replace:=wdReplaceOne
If .Find.Forward = True Then
.Collapse Direction:=wdCollapseEnd
Else
.Collapse Direction:=wdCollapseStart
End If
.Find.Execute
End With
Next i

frmPatrolChoice.Hide

Selection.HomeKey Unit:=wdStory

End Sub
 
D

Doug Robbins - Word MVP

Try

If optFruitOne = True Then
strFruit = "Banana "
With ActiveDocument
Tables(4).Cell(2, 2).Range.Text:="/70"
Tables(7).Cell(2, 2).Range.Text:="/70"
Tables(10).Cell(2, 2).Range.Text:="/70"
Tables(13).Cell(2, 2).Range.Text:="/70"
End With
End If


--
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, originally posted via msnews.microsoft.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top