[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

VBA Word ¦ Search for contents in Table Cells and delete adjacent row.

Posted on 2007-07-26
3
Medium Priority
?
1,022 Views
Last Modified: 2008-01-09
Hello all,

How can I pinpoint the location of a Cell within a Table, and delete the row underneath it? I have vertically merged cells, and apparently the Rows collection fails.

The Cell contains a keyoword such as: "Application Domain " or "Subdomain " and I want to delete the row under the cells which contain any of these strings.

Should I look into a Macro that uses the Search Function, or somehow run through each cell of the Table?

What is a clever way of dealing with this?


Thank you very much,
0
Comment
Question by:vRisc
2 Comments
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 2000 total points
ID: 19575697
Manipulating tables with merged cells is extremely difficult.

This might work, depending on the exact layout of the table.


Sub DeleteNextRow()
    Dim cl As Cell
    Dim cl1 As Cell
    Dim rngFind As Range
    Dim rngCells As Range
    Dim tbl As Table
    Dim v As Integer
    Dim v1 As Integer
    Dim cs As Long
   
    Set tbl = ActiveDocument.Tables(1)
    Set rngFind = tbl.Range
    'Dim h As Integer
    If rngFind.Find.Execute("Application Domain") Then
        For Each cl In tbl.Range.Cells
            If rngFind.InRange(cl.Range) Then
                Exit For
            End If
        Next cl
    v = cl.Range.Information(wdStartOfRangeRowNumber)
   
    Do
        Set cl = cl.Next
        Debug.Print cl.Range.Text
    Loop Until cl.Range.Information(wdStartOfRangeRowNumber) > v
    v1 = cl.Range.Information(wdStartOfRangeRowNumber)
   
    cs = cl.Range.Start
    Do
        Set cl = cl.Next
    Loop Until cl.Range.Information(wdStartOfRangeRowNumber) > v1
    Set cl = cl.Previous
    Set rngCells = ActiveDocument.Range(cs, cl.Range.End)
    rngCells.Cells.Delete wdDeleteCellsEntireRow
    End If
End Sub
0
 

Author Comment

by:vRisc
ID: 19580917
That is simply great, thank you.

One last question: How can I have rngFind.Find.Execute() search for either "Application Domain" OR "Subdomain". In my table, an Application Domain can have 1 or more Subdomains.

The order it finds the rows is important, as I want to modify this code to copy the Description row together with the current Domain row to a different file.

Thanks a bunch, this was lovely.

0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question