bigjaker
09-18-2007, 12:20 PM
I am in need of a macro that will go from table to table in a file until it reaches the end of the file making changes. I will include what I have so far. I need to find some text that is specific to this table and then in that same column (column 4) need to have all the numbers change from 5 digits to the right of the decimal to 3 digits (ex. 3.25102 to 3.251). Basically deleting the right 2 numbers no matter what they are. Once it scrolls through that table column it needs to find the next table in the document with the same word in the header and repeat the process. Each of these tables are 5 columns wide, with a header row, there are no merged cells, but the tables might be 2 rows (including the heading row) or much longer.
Sub Macro4()
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Test1"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Dim oCell As Cell
'Select the fourth cell in the first row of the table
Selection.Tables(1).Cell(1, 4).Select
'Select column 4
Selection.SelectColumn
'Operate on the cells in column 4
For Each oCell In Selection.Cells
Selection.Find.ClearFormatting
With Selection.Find
.Text = "."
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=4
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Next oCell
Application.GoBack
End Sub
I have tried to set up a loop and can't get it to work either.
Any help would be much appreciated. - Jake
Sub Macro4()
Selection.Find.ClearFormatting
With Selection.Find
.Text = "Test1"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
Dim oCell As Cell
'Select the fourth cell in the first row of the table
Selection.Tables(1).Cell(1, 4).Select
'Select column 4
Selection.SelectColumn
'Operate on the cells in column 4
For Each oCell In Selection.Cells
Selection.Find.ClearFormatting
With Selection.Find
.Text = "."
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=4
Selection.Delete Unit:=wdCharacter, Count:=1
Selection.Delete Unit:=wdCharacter, Count:=1
Next oCell
Application.GoBack
End Sub
I have tried to set up a loop and can't get it to work either.
Any help would be much appreciated. - Jake