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 8823413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:20:58+00:00 2026-06-14T06:20:58+00:00

I wrote a crude function to select and concatenate cells based on a range.

  • 0

I wrote a crude function to select and concatenate cells based on a range.

Function GetSkills(CellRef As String, CellRefEnd As String, Delimiter As String)

    Dim CellStart As Range
    Dim CellEnd As Range
    Dim LoopVar As Long
    Dim StartRow As Long
    Dim EndRow As Long
    Dim Concat As String
    Dim Col As Long

    Set CellStart = Worksheets(1).Cells.Range("B" & CellRef)
    Set CellEnd = Worksheets(1).Cells.Range("B" & CellRefEnd)

    Col = CellStart.Column
    StartRow = CellStart.Row
    EndRow = CellEnd.Row

    With Range(CellStart, CellEnd)
        .Merge
        .WrapText = True
    End With

    Concat = ""

    For LoopVar = StartRow To EndRow
        Concat = Concat & Cells(LoopVar, Col).Value
        If LoopVar <> EndRow Then Concat = Concat & Delimiter & " "
    Next LoopVar

    GetSkills = Concat

End Function

Within it I’m trying to merge the cells, when I run the function I get a prompt saying:

The selection contains multiple data values. Merging into once cell
will keep the upper-left most data only

I click OK and Excel crashes, restarts, and prompts the dialog again. Is there another way to merge a block of cells using VBA?

  • 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-14T06:20:59+00:00Added an answer on June 14, 2026 at 6:20 am

    Generally merging cells is not a good idea. It is a cosmetic formatting approach that can cause havoc with VBA code.

    Disclaimers aside, a few suggestions

    • use a Sub rather than a Function given you want to work with altering the range
    • use Application.DisplayAlerts to suppress the merge cells message
    • you can cut down the code significantly

    code

    Sub Test()
    Call GetSkills(2, 4, ",")
    End Sub
    
    Sub GetSkills(CellRef As String, CellRefEnd As String, Delimiter As String)
    Dim CellStart As Range
    Dim CellEnd As Range
    Dim Concat As String
    
    Application.DisplayAlerts = False
    Set CellStart = Worksheets(1).Cells.Range("B" & CellRef)
    Set CellEnd = Worksheets(1).Cells.Range("B" & CellRefEnd)
    
    Concat = Join(Application.Transpose(Range(CellStart, CellEnd)), Delimiter)
    
    With Range(CellStart, CellEnd)
        .Merge
        .WrapText = True
        .Value = Concat
    End With
    Application.DisplayAlerts = True
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is a crude korn shell script that someone else wrote. I don't know
I wrote a function to return a generator containing every unique combination of sub-strings
Wrote a quick Java proggy to spawn 10 threads with each priority and calculate
I wrote a symfony task to fill a database of sample data. Here's a
I wrote a process explorer using C with GUI interface. I want to add
I wrote some script in a site. The script makes a new spreadsheet and
I wrote a simple XML file and a DTD file including an entity, but
I wrote a collada loader for my model viewer. Write now it loops through
I wrote a C++ DLL and it has been compiled. It requires Visual C++
I wrote a PHP script that retrieves values from a MySQL Query. I used

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.