briannnnleong
New Member
- Joined
- May 17, 2022
- Messages
- 2
- Office Version
- 365
- Platform
- Windows
Sub MergeCells()
Dim FirstCell As Range
Dim SecondCell As Range
Set FirstCell = Cells(EmptyRow, 2)
Set SecondCell = Cells(EmptyRow + 8, 2)
With Range(FirstCell, SecondCell)
.Merge
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
End Sub
Thanks for your help but I'll have an error saying "Application-defined or object-defined error" on the statement of set firstcell = ...What you were trying to align here? The syntax is not correct. Should be something like
VBA Code:Sub MergeCells() Dim FirstCell As Range Dim SecondCell As Range Set FirstCell = Cells(EmptyRow, 2) Set SecondCell = Cells(EmptyRow + 8, 2) With Range(FirstCell, SecondCell) .Merge .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter End With End Sub
You have
xlLeft
xlRight
xlJustify
xlCenterAcrossSelection