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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:58:33+00:00 2026-05-27T18:58:33+00:00

Since my previous post was closed, but the problem remains, I’ll rephrase it here.

  • 0

Since my previous post was closed, but the problem remains, I’ll rephrase it here. I’ve came up with the following:

Function JoinLastInColIfEmpty(range_ As Range, delim_ As String)
    Dim cell As Range, result As String, current As String

    For Each cell In range_
        current = LastNonEmptyInCol(cell)
        If current <> "" Then
            result = result & current & delim_
        End If
    Next

    If Not IsEmpty(result) Then
        result = Left(result, Len(result) - Len(delim_))
    End If

    JoinLastInColIfEmpty = result
End Function

Function LastNonEmptyInCol(cell_ As Range)
    Dim tmp As Range
    tmp = cell_ '<< The problem occurs here
    Do Until Not IsEmpty(tmp) Or tmp.Row = 1
        tmp = tmp.Offset(-1, 0)
    Loop
    LastNonEmptyInCol = tmp.Value
End Function

The problem is that the function never ends, so my questions are:

  • What is wrong with my script?
  • What should I do to solve my problem?
  • 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-05-27T18:58:34+00:00Added an answer on May 27, 2026 at 6:58 pm

    To answer your direct question, there are a couple of errors in LastNonEmptyInCol

    Function LastNonEmptyInCol(cell_ As Range)
        On Error Resume Next
        Dim tmp As Range
        Set tmp = cell_ '<< The problem occurs here  ' <<<<< use Set
        Do Until Not IsEmpty(tmp) Or tmp.Row = 1     ' <<<<< use tmp not cell_
            Set tmp = tmp.Offset(-1, 0)              ' <<<<< use Set 
        Loop
        LastNonEmptyInCol = tmp.Value
    End Function
    

    That said, I think it is a very inefficient solution, and does not quite solve your stated problem

    results will be

        A  |  B  |  C  |  D  | Concat
      -----+-----+-----+-----+---------
        1  |  2  |  X  |  5  | 12X5
           |     |  f  |  3  | 12f3
           |  5  |  R  |  12 | 15R12
        Z  |  3  |  T  |     | Z3T12
           |  G  |     |     | ZGT12
    

    Here’s another version which might be better

    Function MyJoinLastInColIfEmpty(range_ As Range, delim_ As String)
        Dim vData As Variant
        Dim cl As Range
        Dim i As Long
        Dim result As Variant
    
        vData = range_
    
        For i = 1 To UBound(vData, 2)
            If vData(1, i) = "" Then
                Set cl = range_.Cells(1, i).End(xlUp)
                If cl <> "" Then
                    vData(1, i) = cl.Value
                End If
            Else
                Exit For
            End If
        Next
        For i = 1 To UBound(vData, 2)
            result = result & vData(1, i) & delim_
        Next
    
        MyJoinLastInColIfEmpty = Left(result, Len(result) - Len(delim_))
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is in continuation to my previous post located here . Since there
Refer to this post for discussions on previous versions. Asking the question again since
I'm continuing a previous post , but I thought I'd open a new thread
Thought I'd give credit where it was due since my previous post was answered
Since I can't post an answer to my previous question yet, I decided to
I was following a previous post on this that says: For LinkedList get is
From a previous post, I have the following view in sqlite3: CREATE View AttendeeTableView
Since CS3 doesn't have a web service component, as previous versions had, is there
That's a question really similar to this previous post of mine. I need to
With respect to my previous post Previous Post I have a Parent table A

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.