Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8748725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:34:30+00:00 2026-06-13T12:34:30+00:00

I need to merge cells using a formula so that the cells only merge

  • 0

I need to merge cells using a formula so that the cells only merge when cells on another tab are filled.
I have 2 tabs with the same amount of columns in each. I want cells a1-d1 to merge in tab 1 when cells a1-d1 in tab 2 are filled and for the value of d1 in tab 2 to be inputted into the newly merged cells in tab 1.
this is what I have:

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:34:31+00:00Added an answer on June 13, 2026 at 12:34 pm

    Excel VBA Methods and Function (Excel Macros) overview

    Since you want to change cells i do not believe that you can use a formula (even not a user defined one). Therefore i wrote an excel vba macro for your problem.

    • FirstRows(): Is the starting point. It loops over 10 rows and calls the other methods
    • CheckEmptyCellValues(curRow): This method checks for empty cells in tab2 (sheet 2 in excel)
    • MergeCells(curRow) takes the current row as a number (any integer from 1 to max amount of rows) and merges the cells from column 1 to 4 on Sheet 1 (the first sheet in excel)

    Fully working demo tested with 4 columns and 10 rows

    Sub FirstRows()
       Sheets(1).Select
       For curRow = 2 To 11
          Merge = CheckEmptyCellValues(curRow)
          If Merge = 4 Then
            MergeCells (curRow)
            cellValue = Sheets(2).Cells(curRow, 4).Value
            Sheets(1).Cells(curRow, 1).Value = cellValue
          End If
       Next
     End Sub
      
    Sub MergeCells(curRow)
        Sheets(1).Select
        Range(Cells(curRow, 1), Cells(curRow, 4)).MergeCells = True
    End Sub
    
    Function CheckEmptyCellValues(curRow)
        Merge = 0
        Sheets(2).Select
        For i = 1 To 4
            If Len(Cells(curRow, i).Value) > 0 Then
                Merge = Merge + 1
            End If
        Next
        CheckEmptyCellValues = Merge
    End Function
    

    Below you can see the result. The values from sheet 2 haven been copied to sheet 1 (second image). In Sheet 1 the Cells in a row are merged (in row 2 from Cell A2 up to Cell D2 (A2-D2 is now just one cell) if in the first image (sheet 2) every cell (from column a to column d) in a row had a value.

    The data source from tab 2 (sheet 2)
    The merged cells and copied values on sheet 1

    Bugs in the modified code

    There are a few things in the modifiend code that are not possible or could lead to a wrong understanding

    Function CheckEmptyCellValues(curColumn) 
      Merge = 0 
      Sheets(2).Select 
      For i = A To d 
        If Len(Cells(curColumn, 11).Value) > 0 Then 
            Merge = Merge + 1 
        End If 
      Next 
      CheckEmptyCellValues = Merge 
    End Function
    
    1. The line For i = A To d is not possible. If you want to use a loop you have to use numbers: For i = 1 To 4 this would repeat the code between For and Next4 times starting with 1
    2. This line Cells(curColumn, 11).Value is technical correct but misleading. Excel uses the first value after (for the row-index and the second value for the column-index. Both values have to be a number: Cells(4,2).Value returns the Cell value from the 4th. row and the second Column (in the Excel Gui the Cell B4)

    Try changing this line For i = A To d to this For i = 1 To 4 and see if that returns the wished result.

    Bugs part 2

    In your other modification you have some of the same bugs:

    • The loop For curColumn = A to d needs numbers instead of letters (unless A and d were a variable filled with a number but according to your code sample this is not the case
    • The line cellValue = Sheets(2).Cells(curColumn, d).Value has the same bug, if d is just the letter d and not something like d = 4 than you can not use it in a loop.

    This is the code from your comment:

     Sub FirstRows() 
      Sheets(1).Select 
        For curColumn = A To d 
           Merge = CheckEmptyCellValues(curColumn) 
           If Merge = d Then 
              MergeCells(curColumn) 
              cellValue = Sheets(2).Cells(curColumn, d).Value 
              Sheets(1).Cells(curColumn, d).Value = cellValue 
           End If
        Next 
      End 
      Sub Sub MergeCells(curColumn) 
         Sheets(1).Select 
         Range(Cells(curColumn, 1), Cells(curColumn, d)).MergeCells = True 
      End Sub
    

    Be carefull it is not running.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to merge cells in Excel (xlsx) by rows and again by columns
I need to merge between dev and master frequently. I also have a commit
All, I need your help to merge the result in the same datetime in
I have multiple tables that need to be merged into one. SELECT name, SUM(money)
Short Version I have a list of int s that I need to figure
I'm using DevExpress XtraGrid and faced with problem. When cells in under the same
I need to merge multiple arrays together, but I only want to KEEP the
I need to merge multiple dictionaries, here's what I have for instance: dict1 =
I need to merge any missing rows in a production mysql database from a
I need to merge two SELECT statements. There are two tables in my database,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.