Results 1 to 4 of 4

Thread: Formatting Problem while copying data

  1. #1
    Member
    Join Date
    Nov 2011
    Posts
    41
    Rep Power
    0

    Formatting Problem while copying data

    Hi All,


    How to copy data of merged cells into a cell. How it can be done from VBA.Please respond.


    Thanks in Advance...

  2. #2
    Member Rajan_Verma's Avatar
    Join Date
    Sep 2011
    Posts
    81
    Rep Power
    13
    You can unmerge cells after pasting data at destination.

    Rajan

  3. #3
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,122
    Rep Power
    10
    Hi

    Your question is not clear to me. Merged cells always create headache. Better to unmerge them and fill the blank cells with the above data.

    Something like

    Code:
    Sub kTest()
        
        Dim rngRange    As Range
        
        Set rngRange = Range("a2:b10")       '<< adjust to suit
        
        With rngRange
            .UnMerge
            On Error Resume Next
            .SpecialCells(4).FormulaR1C1 = "=r[-1]c"
            .Value = .Value
        End With
        
    End Sub
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  4. #4
    Forum Guru Rick Rothstein's Avatar
    Join Date
    Feb 2012
    Posts
    659
    Rep Power
    13
    Quote Originally Posted by princ_wns View Post
    How to copy data of merged cells into a cell. How it can be done from VBA.
    Your question is kind of vague and lacking in details, but see if this code line addresses your problem. Let's say your merged cells are C2:F3. You can reference that range either in its entirety or by an one or more set of cells within it for this method. So, you could use any one of the following to copy just the value in that merged range to another cell (for my example, I used cell D8 for the destination cell)...

    Code:
    Range("D8").Value = Range("C2:F3")(1).MergeArea.Value
    Code:
    Range("D8").Value = Range("E2:D3")(1).MergeArea.Value
    Code:
    Range("D8").Value = Range("C2")(1).MergeArea.Value
    Code:
    Range("D8").Value = Range("F3")(1).MergeArea.Value
    Code:
    Range("D8").Value = Range("D3")(1).MergeArea.Value
    All of the above copy just the value in the merged cells C2:F3 into the cell D8. So, using the setup I show above, any cell or cells in the merged area may be used to transfer the value in the merged area to another cell.
    Last edited by Rick Rothstein; 04-03-2012 at 07:34 PM.

Similar Threads

  1. Solve Block If Without End If Problem
    By jffryjsphbyn in forum Excel Help
    Replies: 3
    Last Post: 06-12-2013, 11:06 AM
  2. Replies: 8
    Last Post: 05-21-2013, 06:34 AM
  3. Copying formulas while keeping formating
    By Bradh in forum Excel Help
    Replies: 1
    Last Post: 12-02-2012, 11:32 AM
  4. Replies: 10
    Last Post: 11-27-2012, 08:27 PM
  5. copying data from multiple workbooks into another
    By rahulcoolz99 in forum Excel Help
    Replies: 1
    Last Post: 08-22-2012, 09:19 PM

Posting Permissions

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