Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 09-08-2019, 08:53 AM
Iput Iput is offline How to merge empty cells before "ok" with a for loop Windows 10 How to merge empty cells before "ok" with a for loop Office 2007
Novice
How to merge empty cells before "ok" with a for loop
 
Join Date: Sep 2019
Posts: 4
Iput is on a distinguished road
Default How to merge empty cells before "ok" with a for loop

I have the problem with ms word table. How to merge empty cells before "ok" with a for loop and then replace empty cell with text “waiting list”, sample :
#before :
empty
empty
ok
empty
empty
empty
ok
empty
ok

#After :


waiting list
ok
waiting list
ok
waiting list
ok
code :
Sub try()
Dim i As Integer, x As Integer, k As Integer
x = ActiveDocument.Tables(1).Rows.Count
'k = empty cell count before "ok"

For i = 1 To x - 1
With ActiveDocument.Tables(1)
If .Cell(i + 1, 1).Range.Text = Chr(13) & Chr(7) Then
.Cell(Row:=i, Column:=1).Merge MergeTo:=.Cell(Row:=i + k, Column:=1)
End If
End With
Next i

For i = 1 To x - 1
With ActiveDocument.Tables(1)
If .Cell(i, 1).Range.Text = Chr(13) & Chr(7) Then
.Cell(i, 1).Range.Text = “waiting list”
End If
End With
Next i

End Sub

thanks
Reply With Quote
  #2  
Old 09-08-2019, 09:33 AM
gmaxey gmaxey is offline How to merge empty cells before "ok" with a for loop Windows 10 How to merge empty cells before "ok" with a for loop Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,422
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

If the table is a single column table as your example indicates then something like this:

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oCell As Cell
  With ActiveDocument.Tables(1)
    Set oCell = .Cell(1, 1)
    Do
      If oCell.RowIndex = .Rows.Count Then Exit Do
      Do While Len(oCell.Range.Text) = 2 And Len(oCell.Next.Range.Text) = 2
        If oCell.RowIndex = .Rows.Count Then Exit Do
        oCell.Merge oCell.Next
      Loop
      If oCell.RowIndex = .Rows.Count Then Exit Do
      Set oCell = oCell.Next
    Loop
  End With
lbl_Exit:
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #3  
Old 09-08-2019, 09:49 AM
Iput Iput is offline How to merge empty cells before "ok" with a for loop Windows 10 How to merge empty cells before "ok" with a for loop Office 2007
Novice
How to merge empty cells before "ok" with a for loop
 
Join Date: Sep 2019
Posts: 4
Iput is on a distinguished road
Default

it works, thanks sir
Reply With Quote
  #4  
Old 09-08-2019, 10:56 AM
Iput Iput is offline How to merge empty cells before "ok" with a for loop Windows 10 How to merge empty cells before "ok" with a for loop Office 2007
Novice
How to merge empty cells before "ok" with a for loop
 
Join Date: Sep 2019
Posts: 4
Iput is on a distinguished road
Default

thanks, it works
one more, if i want to merge this
https://www.msofficeforums.com/attac...1&d=1567962151

Last edited by Iput; 09-08-2019 at 06:09 PM.
Reply With Quote
  #5  
Old 09-08-2019, 01:20 PM
gmaxey gmaxey is offline How to merge empty cells before "ok" with a for loop Windows 10 How to merge empty cells before "ok" with a for loop Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,422
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

Your link is invalid and won't open
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #6  
Old 09-08-2019, 06:10 PM
Iput Iput is offline How to merge empty cells before "ok" with a for loop Windows 10 How to merge empty cells before "ok" with a for loop Office 2007
Novice
How to merge empty cells before "ok" with a for loop
 
Join Date: Sep 2019
Posts: 4
Iput is on a distinguished road
Default

thanks, it works
one more, if i want to merge this with loop
Attached Images
File Type: jpg merge.jpg (95.2 KB, 15 views)

Last edited by Iput; 09-08-2019 at 08:34 PM.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to merge empty cells before "ok" with a for loop Mail Merge Using Rules "IF" to add additional Text Based On Merge Field Content Alfred Mail Merge 2 05-23-2017 10:59 PM
In Excel 2007-After Selecting Visibe Cells-How do I "Copy to Visible cells" Only mag Excel 0 10-28-2012 08:04 PM
'Linking' entered information to other "cells" from an original "cell" in MS Word Wade Word 6 09-03-2012 05:22 PM
How to merge empty cells before "ok" with a for loop Is the a way to delete the "empty" paragraphs? Jamal NUMAN Word 3 07-27-2011 04:19 AM
How to merge empty cells before "ok" with a for loop How to choose a "List" for certain "Heading" from "Modify" tool? Jamal NUMAN Word 2 07-03-2011 03:11 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 02:42 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft