Error With Setting A 'mergearea'

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,570
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
With reference to this code:

Rich (BB code):
Sub blks_setup()
    Dim ws_blocks As Worksheet
    Dim rng_src As Range
    Dim rng_dest As Range
    Dim mergeRange As Range
    
    mbevents = False
    
    Set ws_blocks = ActiveWorkbook.Worksheets("Blocks")
    Set rng_dest = ws_form.Range("G8")
    
    If rcode Like "D*" Then
        Set rng_src = ws_blocks.Range("A1:T5")
        ws_form.Unprotect
        With rng_dest
            .Validation.Delete
            .Cells.UnMerge
            .ClearContents
        End With
        
        rng_src.Copy _
            Destination:=rng_dest
        With ws_form
            With .Range("K8:L8") ', K9:L9, K10:L10, K11:L11, K12:L12, Q8:R8, Q9:R9, Q10:R10, Q11:R11, Q12:R12, T9:Z12")
                If .MergeCells = True Then
                    Set mergeRange = .MergeArea
                    mergeRange.Locked = True
                End If
            End With
        End With
       
     Else
        MsgBox "Error: Block options"
       Stop
     End If
      
End Sub

The line in red is giving me an "Application-defined or object-defined error". The line is part of a process to lock a merged cell. (Yeah ... merged cells. Avoid them. In my application though, the funtionality depends on a range being merged.)

Is anyone able to identify my error?
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
From the Help on Range.MergeArea:
Remarks
The MergeArea property only works on a single-cell range.
therefore you need
VBA Code:
Set mergeRange = .Cells(1).MergeArea
 
Upvote 0
could you concatenate the two values or use "&" and dispaly with centreacross
 
Upvote 0
Hello Peter, thank you. That makes sense.
 
Upvote 0

Forum statistics

Threads
1,223,920
Messages
6,175,374
Members
452,638
Latest member
Oluwabukunmi

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