coliervile
Well-known Member
- Joined
- May 19, 2006
- Messages
- 724
I have a range of cells on Sheet1, (“C2:N35”), that have values/text in. Some cells are empty and I want to merge the blank cells to the cells above with values/text in the same column. I though that the following macro would work, macro is in Module1. When I run the macro I get the following error “Run-time error ‘438’: Object Doesn't Support This Property or Method". I don’t know where to fix the error. Where have I gone wrong??? I’m running Excel 2016.
Thanks,
Charlie
Option Explicit
Sub MergeCells()
Dim LRow As Long
Dim MyRng As Range
Dim c As Range
Dim MergRng As Range
Worksheets(“Sheet1”).Active
Range("C2").Activate
LRow = ActiveCell.CurrentRegion.Rows.Count
Set MyRng = Range("C2:N35”)
For Each c In MyRng
If c.Value = "" Then
Set MergRng = Range(c, c.Offset(-1, 0))
With MergRng.Cells
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlTop
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = True
End With
End If
Next c
End Sub
Thanks,
Charlie
Option Explicit
Sub MergeCells()
Dim LRow As Long
Dim MyRng As Range
Dim c As Range
Dim MergRng As Range
Worksheets(“Sheet1”).Active
Range("C2").Activate
LRow = ActiveCell.CurrentRegion.Rows.Count
Set MyRng = Range("C2:N35”)
For Each c In MyRng
If c.Value = "" Then
Set MergRng = Range(c, c.Offset(-1, 0))
With MergRng.Cells
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlTop
.WrapText = False
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.MergeCells = True
End With
End If
Next c
End Sub