Hello All -
I need to be able to dynamically merge cells using VBA. I am not very experience with VBA at all. I have pieced together some code based on google searches and finding bits of code here and there, but I keep getting an error saying: "Compile error: Wrong number of arguments or invalid property assignment"
Column C has data in it starting in row 12 and the data range in that column is dynamic. The dynamic ranges needs to always start in cell C12 and merge the cells in C, D and E. So, it will need to start with range C12:E12 and merge those 3 cells. Then the loop will need to go to cell C13 and if it's NOT blank, then merge, C13:E13. The loop will need to continue until it reaches the last NON blank cell in column C starting with cell C12.
I would greatly appreciate any help you could provide!
The code is breaking at the .Range part of the If statement
Below is the code that I have so far:
Sub Merge_Cells()
'
' Merge_Cells Macro
Application.ScreenUpdating = False
Dim i As Long
Dim WS As Worksheet
Dim LastCell As Range
Dim LastCellRowNumber As Long
For i = LastCellRowNumber To 12
Set WS = Worksheets("AUTO-EMAIL")
With WS
Set LastCell = .Cells(.Rows.Count, "C").End(xlUp)
LastCellRowNumber = LastCell.Row
If Cells(i, 1) = "" Then .Range(.Cells(i, 0), .Cells(i, 1), .Cells(i, 2)).Merge
End With
Next i
Application.ScreenUpdating = True
End Sub
Bookmarks