Results 1 to 4 of 4

Thread: [VBA] Merge Cells

  1. #1
    New Member
    Join Date
    Jan 2019
    Posts
    18
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default [VBA] Merge Cells

    Hi there everyone!

    I was wondering if it is possible to merge cells through VBA code, cuz I've been trying to pull it off and it seems I'm getting nowhere, I probably need some extra help So the thing is, I add two new rows at the same time with some data by clicking this button but I need to merge some of the cells in that specific row. Something like this:

    Public Sub SumREGR_MAT()

    Application.ScreenUpdating = False


    Dim y2 As Integer
    Dim Row2 As Integer


    y2 = MAT_02.Application.WorksheetFunction.Max(Range("B:B"))
    Row2 = MAT_02.Cells(Rows.Count, 3).End(xlUp).Offset(1, 0).Row


    MAT_02.Cells(Row2, 2).Value = y2 + 1
    MAT_02.Cells(Row2 + 1, 2).Value = y2 + 1
    MAT_02.Cells(Row2, 3).Value = Now
    MAT_02.Cells(Row2 + 1, 3).Value = Now
    MAT_02.Cells(Row2, 4).Value = "=SUM(MAT_02_EXP!K:K)"
    MAT_02.Cells(Row2 + 1, 4).Value = "=SUM(MAT_02_EXP!K:K)"
    MAT_02.Cells(Row1, 5).Value = "ME5009AAAA0"
    MAT_02.Cells(Row1 + 1, 5).Value = "ME5008AAAA2"
    MAT_02.Cells(Row2, 6).Value = 0.5
    MAT_02.Cells(Row2 + 1, 6).Value = 0.5

    Application.ScreenUpdating = True

    End Sub
    What I need is to merge MAT_02.Cells(Row2, 3) and MAT_02.Cells(Row2 + 1, 3) for example...

  2. #2
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    4,541
    Post Thanks / Like
    Mentioned
    42 Post(s)
    Tagged
    12 Thread(s)

    Default Re: [VBA] Merge Cells

    Try this

    Code:
    Public Sub SumREGR_MAT()
    
    
        Application.ScreenUpdating = False
        Dim y2 As Integer
        Dim Row2 As Integer
        
        y2 = MAT_02.Application.WorksheetFunction.Max(Range("B:B"))
        Row2 = MAT_02.Cells(Rows.Count, 3).End(xlUp).Offset(1, 0).Row
        
        MAT_02.Cells(Row2, 2).Value = y2 + 1
        MAT_02.Cells(Row2 + 1, 2).Value = y2 + 1
        'MAT_02.Cells(Row2, 3).Value = Now
        'MAT_02.Cells(Row2 + 1, 3).Value = Now
        
        MAT_02.Cells(Row2, 3).Resize(2).Merge
        MAT_02.Cells(Row2, 3).Value = Now
        
        MAT_02.Cells(Row2, 4).Value = "=SUM(MAT_02_EXP!K:K)"
        MAT_02.Cells(Row2 + 1, 4).Value = "=SUM(MAT_02_EXP!K:K)"
        MAT_02.Cells(Row1, 5).Value = "ME5009AAAA0"
        MAT_02.Cells(Row1 + 1, 5).Value = "ME5008AAAA2"
        MAT_02.Cells(Row2, 6).Value = 0.5
        MAT_02.Cells(Row2 + 1, 6).Value = 0.5
        
        Application.ScreenUpdating = True
    End Sub
    Regards Dante Amor

  3. #3
    New Member
    Join Date
    Jan 2019
    Posts
    18
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: [VBA] Merge Cells

    It freakin worked mate! I really appreciate it man, for real! :D

  4. #4
    Board Regular DanteAmor's Avatar
    Join Date
    Dec 2018
    Location
    México
    Posts
    4,541
    Post Thanks / Like
    Mentioned
    42 Post(s)
    Tagged
    12 Thread(s)

    Default Re: [VBA] Merge Cells

    I'm glad to help you. Thanks for the feedback.
    Regards Dante Amor

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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