Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-31-2022, 10:53 PM
jamu jamu is offline How can I use Word Vba to insert a blank row after rows with cells containing certain texts? Windows 10 How can I use Word Vba to insert a blank row after rows with cells containing certain texts? Office 2021
Novice
How can I use Word Vba to insert a blank row after rows with cells containing certain texts?
 
Join Date: Mar 2022
Posts: 11
jamu is on a distinguished road
Default How can I use Word Vba to insert a blank row after rows with cells containing certain texts?


How can I use Word Vba to insert a blank row after rows with cells containing certain texts? For example, I want to insert a blank row after a row that has the word "total" in a cell. There are several tables in the document and in each table there can be the word or the word criteria in a row at regular intervals.
Reply With Quote
  #2  
Old 03-31-2022, 11:27 PM
gmayor's Avatar
gmayor gmayor is offline How can I use Word Vba to insert a blank row after rows with cells containing certain texts? Windows 10 How can I use Word Vba to insert a blank row after rows with cells containing certain texts? Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,137
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Assuming no merged cells
Code:
Sub Macro1()
Dim oTable As Table
Dim oRow As Row
Dim i As Integer, j As Integer
    For i = 1 To ActiveDocument.Tables.Count
        Set oTable = ActiveDocument.Tables(i)
        For j = oTable.Rows.Count To 1 Step -1
            Set oRow = oTable.Rows(j)
            If InStr(1, oRow.Range, "total") > 0 Then
                oRow.Range.Rows.Add
            End If
        Next j
    Next i
    Set oTable = Nothing
    Set oRow = Nothing
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 04-01-2022, 01:54 AM
jamu jamu is offline How can I use Word Vba to insert a blank row after rows with cells containing certain texts? Windows 10 How can I use Word Vba to insert a blank row after rows with cells containing certain texts? Office 2021
Novice
How can I use Word Vba to insert a blank row after rows with cells containing certain texts?
 
Join Date: Mar 2022
Posts: 11
jamu is on a distinguished road
Default

Thank you, it worked perfectly, the problem is now solved.
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to combine the texts of all cells in a column without line break. ericliu24 Word VBA 1 03-29-2022 05:28 PM
How can I use Word Vba to insert a blank row after rows with cells containing certain texts? Delete blank rows between the two rows that contain data beginner Excel Programming 5 12-26-2014 12:29 AM
How can I use Word Vba to insert a blank row after rows with cells containing certain texts? Search the text in 3rd cell by using texts in 2 cells Shinaj Excel Programming 1 05-09-2014 09:17 AM
How can I use Word Vba to insert a blank row after rows with cells containing certain texts? Unable to vertically center align texts in table cells? tinfanide Word 3 11-24-2013 06:37 AM
How can I use Word Vba to insert a blank row after rows with cells containing certain texts? How to organize and insert blank cells between a huge number of data? tareq Excel 12 09-29-2010 02:12 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:08 PM.


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