Consulting

Results 1 to 7 of 7

Thread: Copy from Merged Cell to individual cell

  1. #1

    Copy from Merged Cell to individual cell

    Hi..

    I need to get a VBA code to copy data from merged cell to individual cells. Please see the excel sheet format below:
    Copy of Book1.jpg
    Thanks in advance -- Jamshad
    Attached Images Attached Images

  2. #2
    VBAX Expert
    Joined
    Sep 2016
    Posts
    788
    Location
    Option Explicit
    
    
    Sub test()
        Dim c As Range
        Dim f As Range
        Dim s As String
        
        For Each c In Range("d3", Range("d" & Rows.Count).End(xlUp))
        
            Set f = Columns("b").Find(What:=c.Value, LookAt:=xlWhole)
            
            If f Is Nothing Then
                s = ""
            Else
                s = f.Offset(, -1).MergeArea(1).Value
            End If
            c.Offset(, 1).Value = s
        Next
          
    End Sub

  3. #3
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    if you don't mind just converting the merged cells to individual cells then select the merged cells and run:
    Sub blah()
    With Selection
      .MergeCells = False
      .SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
      .Value = .Value
    End With
    End Sub
    Then you can move the columns around.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  4. #4
    Is this dan?

    Thanks for the code, but i cannot convert to individual cells as this is a master file and not recommended to change the format. The file has got 100s of data rows and with multiple sheets,

    Is there any other way.

    Thanks,
    Jamshad

    Quote Originally Posted by p45cal View Post
    if you don't mind just converting the merged cells to individual cells then select the merged cells and run:
    Sub blah()
    With Selection
      .MergeCells = False
      .SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
      .Value = .Value
    End With
    End Sub
    Then you can move the columns around.

  5. #5
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Well copy the columns to a fresh sheet then.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  6. #6

  7. #7
    Thanks, This helps
    Quote Originally Posted by mana View Post
    Option Explicit
    
    
    Sub test()
        Dim c As Range
        Dim f As Range
        Dim s As String
        
        For Each c In Range("d3", Range("d" & Rows.Count).End(xlUp))
        
            Set f = Columns("b").Find(What:=c.Value, LookAt:=xlWhole)
            
            If f Is Nothing Then
                s = ""
            Else
                s = f.Offset(, -1).MergeArea(1).Value
            End If
            c.Offset(, 1).Value = s
        Next
          
    End Sub

Tags for this Thread

Posting Permissions

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