Home |
Search |
Today's Posts |
#1
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Why is saving to a disc suddenly "write protected"? | Microsoft Word Help | |||
I am trying to write music in MS word. Write the words and notes | Microsoft Word Help | |||
Mail Merge - Next Record If Statement | Mailmerge | |||
Possible BUG: Multiple HTTPrequests send from one includetext statement | Mailmerge | |||
Need help with conditional if statement | Mailmerge |