Reply
 
Thread Tools Display Modes
  #1   Report Post  
Perplexed
 
Posts: n/a
Default How can I write an If, Then, Else statement in Microsoft Word

I have a Microsoft Word table that has seven cells in the row. Some of the
cells have text in them already and some do not. I want to move the text
from the first cell to one of the empty cells. I need to write an If
statement that will test if the cell I'm moving the text into is empty before
it pastes the text in it. If the cell is empty, then paste the text into
that cell, if it's not empty, then move to the next cell to the right and
test if that cell is empty before pasting the text. It should test for an
empty cell five times before ending the If statement. Can anyone help me to
write an If statement to accomplish this?
  #2   Report Post  
Greg Maxey
 
Posts: n/a
Default

Perplexed,

You can to this with a macro. I would use Select Case vice IFThenElse.

Sub MoveText()
Dim oTbl As Table
Dim txtString As String

Set oTbl = ActiveDocument.Tables(1)
txtString = oTbl.Cell(1, 1).Range.Text
Select Case 2
Case Len(oTbl.Cell(1, 2).Range.Text)
oTbl.Cell(1, 2).Range.Text = txtString
Case Len(oTbl.Cell(1, 3).Range.Text)
oTbl.Cell(1, 3).Range.Text = txtString
Case Len(oTbl.Cell(1, 4).Range.Text)
oTbl.Cell(1, 4).Range.Text = txtString
Case Len(oTbl.Cell(1, 5).Range.Text)
oTbl.Cell(1, 5).Range.Text = txtString
Case Len(oTbl.Cell(1, 6).Range.Text)
oTbl.Cell(1, 6).Range.Text = txtString
Case Len(oTbl.Cell(1, 7).Range.Text)
oTbl.Cell(1, 7).Range.Text = txtString
Case Else
MsgBox "All cells are in use."
End Select

End Sub


--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

Perplexed wrote:
I have a Microsoft Word table that has seven cells in the row. Some
of the cells have text in them already and some do not. I want to
move the text from the first cell to one of the empty cells. I need
to write an If statement that will test if the cell I'm moving the
text into is empty before it pastes the text in it. If the cell is
empty, then paste the text into that cell, if it's not empty, then
move to the next cell to the right and test if that cell is empty
before pasting the text. It should test for an empty cell five times
before ending the If statement. Can anyone help me to write an If
statement to accomplish this?



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Why is saving to a disc suddenly "write protected"? mickey h Microsoft Word Help 2 May 28th 05 05:28 AM
I am trying to write music in MS word. Write the words and notes B Microsoft Word Help 1 May 1st 05 11:28 PM
Mail Merge - Next Record If Statement HiramPat Mailmerge 5 April 22nd 05 04:03 PM
Possible BUG: Multiple HTTPrequests send from one includetext statement Oliver Mailmerge 2 April 18th 05 09:46 AM
Need help with conditional if statement Jan Mailmerge 1 March 24th 05 09:14 PM


All times are GMT +1. The time now is 05:02 AM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"