Fixing Run-Time Error 438

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
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Code:
Worksheets(“Sheet1”).[COLOR="#FF0000"]Select[/COLOR]
 
Upvote 0
Thank you “shg” for looking at my problem. I change Active to Select and I get the same error. When I debug it highlights “Range(C2”).Active
 
Last edited:
Upvote 0
You have open & closing quotes around Sheet1. VBA uses straight quotes.
 
Upvote 0
Replace both lines with

Code:
Application.GoTo Worksheets("Sheet1").Range("C2")
 
Upvote 0
“shg” I save the change you recommended and the macro ran, but it did run as I had hoped. Some cells merged, but they didn’t merge with the cells above with valid/text. When I run the macro I get the following Excel message “Merging cells only keeps the upper-left value and discards other values.” All the values remained on the sheet and when I debugged it it highlights “.MergeCells = True”
 
Upvote 0
Making the Application change gives a “Compile error: Expected Function or variable” and highlights “.GoTo”
 
Upvote 0
The universal solution to problems with merged cells is to not merge cells.
 
Upvote 0
Hi,
Try changing the following two lines accordingly. It may help.
Code:
If c.Offset(1,0).value <> "" Then
Set MergRng = Range(c, c.Offset(1, 0))
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top