Consulting

Results 1 to 7 of 7

Thread: Solved: Locking Merged Cells

  1. #1
    VBAX Regular tools's Avatar
    Joined
    Apr 2008
    Posts
    70
    Location

    Solved: Locking Merged Cells

    Hi all,

    I have a cell which is merged with another cell , say B6 and C6
    now is there a way to lock these cells..?

    And if i want to retrieve the value entered in that merged cell then is there a way to do that using vba.?
    Regards

    If I look its because i'm

  2. #2
    Site Admin VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,005
    Location
    Try playing around with this:
    [vba]
    Sub Lock_Merged_Copy_Merged()
    Range("B6:C6").Locked = True
    Range("B6:C6").Copy
    Range("A1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Application.CutCopyMode = False

    End Sub
    [/vba]remember that "Locked" cells are not locked unless the woorksheet is protected!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  3. #3
    VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    I would avoid merged cells. Try formatting for "center across selection instead. I have had so much trouble with files with merged cells that I almost refuse to work on one.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  4. #4
    VBAX Regular tools's Avatar
    Joined
    Apr 2008
    Posts
    70
    Location
    Thanks Simon

    Is there a way to directly copy the value inside a variable or do i need to pick that value from cell A1.?
    Regards

    If I look its because i'm

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Just set the cell value to the variable, the first cell of the merged cells.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    Site Admin VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,005
    Location
    Exactly as Bob explained, i only pasted the value to A1 so you could see the code in action showing you that neither the source cell nor the destination cell were selected (you don't have to select an object in order to work with it), you can paste to whichever cell you like!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  7. #7
    VBAX Regular tools's Avatar
    Joined
    Apr 2008
    Posts
    70
    Location
    Thanks a lot guys

    Regards

    If I look its because i'm

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •