Darren Smith
Well-known Member
- Joined
- Nov 23, 2020
- Messages
- 631
- Office Version
- 2019
- Platform
- Windows
Find the * in a text string then merge the text across the columns.
At the moment it seems to just merge a load of random cells
At the moment it seems to just merge a load of random cells
VBA Code:
Sub MergeCells()
Dim myFirstRow As Long
Dim myLastRow As Long
Dim myCriteriaColumn As Long
Dim myFirstColumn As Long
Dim myLastColumn As Long
Dim ws As Worksheet
Dim myCriteria As String
Dim iCounter As Long
myFirstRow = 13
myCriteriaColumn = 5
myFirstColumn = 5
myLastColumn = 14
myCriteria = "Merge cells"
Set ws = ThisWorkbook.Worksheets("Job Card with Time Analysis")
With ws
myLastRow = .Cells.Find(What:="*", LookIn:=xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
For iCounter = myLastRow To myFirstRow Step -1
If .Cells(iCounter, myCriteriaColumn).Value = myCriteria Then .Range(.Cells(iCounter, myFirstColumn), .Cells(iCounter, myLastColumn)).Merge
Next iCounter
End With
End Sub