I have a master list of items that I copy items from into individual sheets. Each item is a group of rows, and each group of rows is separated from the next group by a empty row that is formatted with bold borders. I only want to copy those columns with data so formulas in the target worksheet are not fouled up. Thus the copied range will be the intersection of the data columns and the rows between bold borders. I am trying to loop up from the current selection to a row with a bold border to find the top of the range, then loop down to find a row with a bold border to find the bottom of the range. But I'm having some trouble with the code. This is what I have so far:
Sub CopyRng()
' Keyboard Shortcut: Ctrl+q
Dim Rng1 As Range
Dim Rng2 As Range
Dim Rng3 As Range
Dim Rng4 As Range
Dim Rng5 As Range
Dim rs As Range
Set Rng1 = Range(Range("E7"), Range("E65536").End(xlUp))
Set Rng2 = Range(Range("G7"), Range("J65536").End(xlUp))
Set Rng3 = Range(Range("L7"), Range("O65536").End(xlUp))
Set Rng4 = Range(Range("Q7"), Range("R65536").End(xlUp))
Set Rng5 = Union(Rng1, Rng2, Rng3, Rng4)
For r = (Selection.End(xlUp).Row) To r = 7 Step -1
With Selection.Borders(xlEdgeTop)
If .Weight = xlMedium Then
t = Selection.Row
End If
End With
Next r
For r = 7 To r = (Selection.End(xlUp).Row) Step 1
With Selection.Borders(xlEdgeBottom)
If .Weight = xlMedium Then
b = Selection.Row
End If
End With
Next r
rs = Range(Cells(t, 1), Cells(b, 18))
Set CopyRng = Intersect(rs, Rng5)
CopyRng.Select
End Sub
Any help is appreciated.
Bookmarks