My Title for this might not make sense as I do not know all of the VBA terminology. Hopefully I can explain enough for the experts on this forum. I have been helped many times on here and the macro I am trying to modify is one that was given to me in one of my earlier posts. This macro looks thru my sheet in column 5 for the word "Materials" and then does a Offset selection, then modifies the color formatting. This Macro works great but now I need to expand it some. Currently the Resize is always 5 rows. I am finding that I may need 5 rows, 6 rows or even 10 rows throughout my sheet. The only unique thing I can think of to end the last selected row, is the last row has unique borders. Is there a way to resize my selection based on a cells border formatting? So instead of "Resize(5, 1)" I need the macro to find the border formatting I show below and end the selection there. Hopefully someone can help here. I have searched this forum for something similar and have come up empty.
Below is the code and I have attached a image of the cell borders that would be in the last selected row.
Below is the code and I have attached a image of the cell borders that would be in the last selected row.
VBA Code:
Sub Macro1()
'
' Macro1 Macro
'
'
Dim fnd As String, FirstFound As String
Dim FoundCell As Range, rng As Range
Dim myRange As Range, LastCell As Range
'What value do you want to find (must be in string form)?
fnd = "Materials"
Set myRange = ActiveSheet.UsedRange.Columns(5)
Set LastCell = myRange.Cells(myRange.Cells.Count)
Set FoundCell = myRange.Find(What:=fnd, after:=LastCell)
'Test to see if anything was found
If Not FoundCell Is Nothing Then
FirstFound = FoundCell.Address
End If
Set rng = FoundCell.Offset(1, 10).Resize(5, 1)
'Loop until cycled through all unique finds
Do Until FoundCell Is Nothing
'Find next cell with fnd value
Set FoundCell = myRange.FindNext(after:=FoundCell)
'Add found cell to rng range variable
Set rng = Union(rng, FoundCell.Offset(1, 10).Resize(5, 1))
'Test to see if cycled through to first found cell
If FoundCell.Address = FirstFound Then Exit Do
Loop
'Select Cells Containing Find Value
rng.Select
With Selection.Font
.Color = -16566529
.TintAndShade = 0
End With
End Sub