Hi!
I have the following code that I borrowed from another thread and tweaked only slightly.
Basically this works beautifully to concatenate a large amount of columns into one and recognize the blank cells as something (in this case a back slash). For my worksheet in a single row my cells either have a word in them or are blank cells between words. So when I apply the above code now I see my result looking something like (purely for example)...Function ConcatRange(inputRange As Range, Optional delimiter As String, Optional delimiter2 As String) As String Dim oneCell As Range With inputRange If Not (Application.Intersect(.Parent.UsedRange, .Cells) Is Nothing) Then For Each oneCell In Application.Intersect(.Parent.UsedRange, .Cells) If oneCell.Text <> vbNullString Then ConcatRange = ConcatRange & delimiter & oneCell.Text End If If oneCell.Text = vbNullString Then ConcatRange = ConcatRange & delimiter2 & oneCell.Text End If Next oneCell ConcatRange = Mid(ConcatRange, Len(delimiter) + 1) End If End With End Function
/ ALL CAPS TOGETHER/// all lower case together////
Here, each back slash (according to the above code) represents one blank cell. What I ACTUALLY want to see is the following:
ALL CAPS TOGETHER/ all lower case together/
so that the words or 'phrases' are still separated by something (again, backslash) but only by ONE. Essentially, taking a series of blank cells and reading each series as a single backslash. Can anyone help?? I can not do these individually as my actual data I'm applying this to is several thousand columns.
Thanks in advance!
Last edited by PennyKat; 12-14-2011 at 06:01 PM. Reason: for clarity
Maybe ...
Function ConcatRange(rCat As Range, Optional sSep As String = "") As String Dim cell As Range Dim rInt As Range Set rInt = Intersect(rCat.Worksheet.UsedRange, rCat) If Not rInt Is Nothing Then For Each cell In rInt If Len(cell.Text) Then ConcatRange = ConcatRange & cell.Text & sSep End If Next cell End If End Function
Microsoft MVP - Excel
Entia non sunt multiplicanda sine necessitate
When I use a space as my delimiter this gives me...
ALL CAPS TOGETHER all lower case together
But I still need to be able to see where my blank cells were (via a single backslash) since this indicates to me the separator of a group of words making a phrase. So I would like to see...
/ ALL CAPS TOGETHER / all lower case together /
(Only red to highlight... I don't need or want the output to have red backslashes.) Does this make sense?
Post a workbook with examples and expected results that cover the waterfront.
Microsoft MVP - Excel
Entia non sunt multiplicanda sine necessitate
Attached is an example of a much smaller version of my real data. I applied my original VBA code to column T. The code is reading from column D through S per row.
Please let me know if this is unclear. Again, I want column T to spit out... for instance...
/ could look like this / here's another phrase / Hi /
You know what, I seriously apologize. Here, if it helps, please take a look at this one. I've added column U to indicate what I want.
What logic did you use to decide that
could look like this/ here's another phrase/ Hi/
dosn't include a leading slash, but
/ALL CAPS TOGETHER /all lower case together /
does?
Microsoft MVP - Excel
Entia non sunt multiplicanda sine necessitate
I used the same code I first mentioned thread. That's the output I got per row. I believe it's due to this line of code...
Like I mentioned, I borrowed some code to build this so I could be mistaken.ConcatRange = Mid(ConcatRange, Len(delimiter) + 1)
That wasn't my question; I was referring to your desired results.
Microsoft MVP - Excel
Entia non sunt multiplicanda sine necessitate
Furthermore, ideally I wouldn't have a leading slash BUT I honestly don't care as long as it's just one and not several. Doesn't make a difference to the way I'm analyzing.
Function ConcatRange(rCat As Range) As String Dim cell As Range Dim rInt As Range Set rInt = Intersect(rCat.Worksheet.UsedRange, rCat) If Not rInt Is Nothing Then For Each cell In rInt If Len(cell.Text) Then ConcatRange = ConcatRange & cell.Text & " " Else If Right(ConcatRange, 1) <> "/" Then ConcatRange = ConcatRange & "/" End If Next cell End If If Left(ConcatRange, 1) = "/" Then ConcatRange = Mid(ConcatRange, 2) End Function
Microsoft MVP - Excel
Entia non sunt multiplicanda sine necessitate
That's beautiful. Thank you for all the help!
You're welcome, good luck.
Microsoft MVP - Excel
Entia non sunt multiplicanda sine necessitate
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks