Macro to identify sections between borders

时间:2017-06-19 13:52:48

标签: excel vba excel-vba

I have a piece of a macro that delineates my data visually with a bottom border:

'   Add line between each item
Sheets("Audit").Select
LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Dim rng As Range
For Each rng In Range("F2:F" & LastRow)
  If rng <> rng.Offset(1, 0) Then
    Range("A" & rng.Row & ":O" & rng.Row).Borders(xlEdgeBottom).LineStyle = xlContinuous
  End If
Next rng

This separates transactions relating to each item into nice little sections. The problem is that, in order to catch everything I need, there is a lot of extraneous data and most sections are not relevant. I have the relevant transactions bolded, but I need to see everything in the same "box" as the bolded transactions, so I can't simply use autofilter.

What I'm trying to get some direction on is somehow filtering out any section between borders that does not contain a bolded line (or only filtering in the sections that do contain a bolded line). Also, the bolded lines are the only lines that have the word "remove" or "override" in column H, if it's easier to do it that way. I'm at a loss on how to solve this even logically, much less with a macro.

Any ideas?

Edit: I've added a helper column in which each row with a bottom border has "Line" in the M column, each bolded Remove transaction has a "Remove" in that column, and most cells in the column are blank. The task now is to develop a macro to delete all rows between the "Lines" that do no contain a "Remove" between them. So in the following example, I would want to delete rows 2-4, keep 5-9, and delete 10-11 (First row in each range is +1 due to the line drawn as a bottom border).

1 Line
2 
3 
4 Line
5
6 Remove
7
8
9 Line
10
11 Line

0 个答案:

没有答案