Renaming a merged cell

camandab

Board Regular
Joined
Feb 10, 2010
Messages
79
Hello,

I'm trying to rename a merged cell and I'm getting the following error and the last line of the code is highlighted when I debug:

Run-time error '70' : Permission denied

Code:
Sub RenameCell()
'
' '
    Sheets(Sheets.Count).Select
    Cells.Find(what:="general ledger", After:=ActiveCell, LookIn:=xlFormulas _
        , LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False).Activate
    Selection.Copy
    ActiveCell.Offset(1, 0).Select
    Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
        SkipBlanks:=False, Transpose:=False
    Application.CutCopyMode = False
    Selection.Name = "January 2010"
End Sub

I think I might be missing something simple. :eeek: Any ideas??
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
One idea would be to not use merged cells, though I'm not actually sure the problem described is due to them.

'Permission Denied' sounds more like some sort of file violation/issue.

Another thing that could be causing problems is the use of Select/Selection etc

They just aren't needed and can cause trouble.:)
 
Upvote 0
I should have mentioned that the cell is part of a template and the merged cell is required. Sometimes the merged cells are not always the same (i.e. cannot use Range("A1:E1") as it could also be Range("B1:E1") which is why I try to copy the format of the cell above, paste, and then rename.

I've tried using ActiveCell rather than Selection and another error "That name is not valid".
 
Upvote 0
I wouldn't recommend using ActiveCell either.

If you want to search for something then try something like this.
Code:
Option Explicit

Sub RenameCell()
Dim rngFnd As Range
    ' '
    With Sheets(Sheets.Count)
        Set rngFnd = .Cells.Find(what:="general ledger", After:=.Range("A1"), LookIn:=xlFormulas _
                                                                                      , LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
                                 MatchCase:=False)
        If Not rngFnd Is Nothing Then
            rngFnd.Copy
            rngFnd.Offset(1).PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, _
                                          SkipBlanks:=False, Transpose:=False
            rngFnd.Offset(1).Name = "January2010"
        End If
    End With
 
    Application.CutCopyMode = False

End Sub
Oh, and you can't have spaces in range names.:)
 
Upvote 0

Forum statistics

Threads
1,222,830
Messages
6,168,509
Members
452,194
Latest member
Lowie27

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