how to fill all cells that are empty in a table with a hyphen?

G

Gil Carter

Hi All,

How does one put a hyphen in all empty cells in a table?
tia
Gil

Some of my efforts are:
Sub a1()
'
' a1 macro
'
'
Selection.MoveRight Unit:=wdCell

Dim MyVar, MyCheck
MyCheck = IsNull(MyVar) ' Returns False.

'MyVar = ""
'MyCheck = IsNull(MyVar) ' Returns False.'

'MyVar = Null
'MyCheck = IsNull(MyVar) ' Returns True.


MyVar = Selection.Text

If MyCheck = IsNull(MyVar) = True Then
Selection.TypeText Text:="-"
ElseIf MyCheck = IsNull(MyVar) = False Then

' End If

' If MyVar = Null Then
' Selection.TypeText Text:="-"
' ElseIf MyCheck = False Then
' End If
End If
End Sub
 
H

Helmut Weber

Hi Gil,
for the first table that is touched by the selection:

Dim c As Cell
For Each c In Selection.Tables(1).Range.Cells
If Len(c.Range.Text) = 2 Then
c.Range.Text = "-"
End If
Next

There may be faster ways, though,
but not many, probably.

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
J

Jezebel

Don't understand your code at all, but perhaps what's throwing you off is
that every cell -- including empty cells -- contains a minimum of two
characters: chr(13)chr(7).

Dim pCell as Word.Cell
pCell = Selection.Tables(1).Cell(1,1)
Do
If len(pCell.Range) = 2 then
pCell.Range = "-"
end if
set pCell = pCell.Next
Loop until pCell is nothing
 

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

Top