Hello,
I'm trying to search through a set of cells, find matches and merge the cells that match adjacent ones. What I have so far works fine but I suppose I may be going about this the wrong way. I want to search through the displayed value. In my case, it's a series of dates that are formatted to show only the month. I'd like to go through and merge all matching months out of them. So for May, I'd like it to find all twenty workdays, match the month, and then merge those cells. The cells contain simple formulas like this
I'm trying to search through a set of cells, find matches and merge the cells that match adjacent ones. What I have so far works fine but I suppose I may be going about this the wrong way. I want to search through the displayed value. In my case, it's a series of dates that are formatted to show only the month. I'd like to go through and merge all matching months out of them. So for May, I'd like it to find all twenty workdays, match the month, and then merge those cells. The cells contain simple formulas like this
=WORKDAY(AH4,1)
that build out a work day calendar. I'm likely on the wrong path, here, since I seem to have a habit of that but any help would be appreciated.
VBA Code:
Option Explicit
Sub Merge_Same_rngs()
Application.DisplayAlerts = False
Dim rng As Range
Mergerngs:
For Each rng In Sheets("Sheet1").Range("J3:ZZ3")
If rng.Value = rng.Offset(0, 1).Value And rng.Value <> "" Then
Range(rng, rng.Offset(0, 1)).Merge
Range(rng, rng.Offset(0, 1)).HorizontalAlignment = xlCenter
Range(rng, rng.Offset(0, 1)).VerticalAlignment = xlCenter
GoTo Mergerngs
End If
Next
End Sub