Combining Cells on Loop until Last Character equal >

keeblerkev

New Member
Joined
Apr 2, 2012
Messages
23
Hello,

I have had great success with people's help on this site and hoping the success continues with this problem. I have two parts to my spreadsheet that I am struggling with in regardsin to combining cells.

Part 1:
My spreadsheet comes looking like this below:
| A | B | C | D | E |...
|<FONT>How | Who | What | Why | ?<BR></FONT></P> |

I need this to be combined all in one cell to read: <FONT>How, What, Why, ?<BR></FONT></P> (Including commas between values that were in separate cells)

The catch is that in this example it goes to Column E, but it various from each spreadsheet on where the question ends. The constants is that the question always starts at Coulmn D and the last cell always ends with </P>.

Is there a way to run a loop to combine these cells until the last character is ">"?

PART 2:
Following the combining in part 1, I need a loop that will combine cells until it reaches a blank cell. Once part 1 works, the constant would be that this data would start in Column E and then continue until a blank cell.

Please let me know if i my dreams of making this spreadsheet user friendly is just out of reach.

Thank you,
Kev
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Try this:-
NB:_ Results to "A1":- Alter to suit !!!!
Code:
[COLOR="Navy"]Sub[/COLOR] MG04Apr02
[COLOR="Navy"]Dim[/COLOR] Temp        [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
[COLOR="Navy"]Dim[/COLOR] RngAc       [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] Ac          [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Set[/COLOR] RngAc = Range("D1", Cells(1, Columns.Count).End(xlToLeft))
         [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Ac [COLOR="Navy"]In[/COLOR] RngAc
         Temp = Temp & ", " & Ac
         [COLOR="Navy"]If[/COLOR] InStr(Ac, ">") > 0 [COLOR="Navy"]Then[/COLOR] [COLOR="Navy"]Exit[/COLOR] For
             Ac = vbNullString
              [COLOR="Navy"]Next[/COLOR] Ac
               Range("A1") = Mid(Temp, 2)
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0
Good morning CharlesChuckCharles,

You are right, it does work. It was user error with my inputs that were the problem. Unfortunately, I plan to provide this macro to multiple users and would like to reduce the amount of input they need to enter (and reduce error) for these reports.

Any chance being able to make this part of the VBA macro without inputs?
 
Upvote 0
MickG,

This is great! This is an Awesome code. It works great except for the fact that my first cell sometimes starts with "<>" which then stops it. Is there a way it can recognize only the last value in the cell and stop only when that value is = ">"?

Also I need to be able to delete only the cells it combined. so is there a way to delete these cells, and shift everything to the left?

I feel like we are so close to actually making this work. I tried the code below but it did won't for some reason. Any ideas?

Code:
Sub MG04Apr02()
Dim Temp        As String
Dim RngAc       As Range
Dim Ac          As Range
Set RngAc = Range("D1", Cells(1, Columns.Count).End(xlToLeft))
         For Each Ac In RngAc
         Temp = Temp & ", " & Ac
          If Right$(Cells(1, Columns.Count).Value2, 1) = ">" Then Exit For
             Ac = vbNullString
              Next Ac
               Range("D1") = Mid(Temp, 2)
End Sub
 
Upvote 0
If the last cell you want to include has the sign >
With no other characters then you can just change that line to:-
Code:
If  ac = ">" Then Exit For
 
Upvote 0
Use this inconjunction with the previous function

Code:
Public Sub JoinCells()
Dim MySep As String
'MySep = Chr(44) & Chr(34) & Chr(32) & Chr(44)

ActiveSheet.Range("D2").Value = jointhecells(Range("E2"), 0, True, ", ", ">")
End Sub

Joincells is the macro you call
 
Upvote 0
Unfortunately, the last cell usually has some like "etc.) < br> < /Font> < /P>"

But it various depending on where the data is coming from, but the last cells I want to combine always ends with something and ">"
 
Upvote 0
You'll need to replace

For Each myCell In myRange
If Not (bDontStop) And myCell.Value = strStopString Then


WITH

For Each myCell In myRange
If Not (bDontStop) And InStr(1, myCell.Value, strStopString) > 0 Then
 
Upvote 0
Perhaps:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG04Apr14
[COLOR="Navy"]Dim[/COLOR] Temp        [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
[COLOR="Navy"]Dim[/COLOR] RngAc       [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Dim[/COLOR] Ac          [COLOR="Navy"]As[/COLOR] Range
[COLOR="Navy"]Set[/COLOR] RngAc = Range("D1", Cells(1, Columns.Count).End(xlToLeft))
         [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] Ac [COLOR="Navy"]In[/COLOR] RngAc
         Temp = Temp & ", " & Ac
         [COLOR="Navy"]If[/COLOR] Right(Trim(Ac), 1) = ">" [COLOR="Navy"]Then[/COLOR] [COLOR="Navy"]Exit[/COLOR] For
             Ac = vbNullString
              [COLOR="Navy"]Next[/COLOR] Ac
               Range("A1") = Mid(Temp, 2)
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,214,942
Messages
6,122,366
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top