Merging selective cells in a Column

hrithik

Active Member
Joined
Jul 26, 2010
Messages
336
I have the following data in Column A:
<TABLE style="BORDER-BOTTOM: #a3a3a3 1pt solid; BORDER-LEFT: #a3a3a3 1pt solid; BORDER-COLLAPSE: collapse; DIRECTION: ltr; BORDER-TOP: #a3a3a3 1pt solid; BORDER-RIGHT: #a3a3a3 1pt solid" border=1 cellSpacing=0 cellPadding=0 valign="top"><TBODY><TR><TD style="BORDER-BOTTOM: #a3a3a3 1pt solid; BORDER-LEFT: #a3a3a3 1pt solid; PADDING-BOTTOM: 4pt; PADDING-LEFT: 4pt; WIDTH: 6.657in; PADDING-RIGHT: 4pt; VERTICAL-ALIGN: top; BORDER-TOP: #a3a3a3 1pt solid; BORDER-RIGHT: #a3a3a3 1pt solid; PADDING-TOP: 4pt">0-618-56866-2,Used*,$68.25,$85.30,79 In Stock,Textbook,Premium,$85.30,,"358 In Stock
</TD></TR><TR><TD style="BORDER-BOTTOM: #a3a3a3 1pt solid; BORDER-LEFT: #a3a3a3 1pt solid; PADDING-BOTTOM: 4pt; PADDING-LEFT: 4pt; WIDTH: 6.657in; PADDING-RIGHT: 4pt; VERTICAL-ALIGN: top; BORDER-TOP: #a3a3a3 1pt solid; BORDER-RIGHT: #a3a3a3 1pt solid; PADDING-TOP: 4pt">500+ Premium Incoming - Available Shortly",Textbook,2,2011-05-23 09:28:01
</TD></TR><TR><TD style="BORDER-BOTTOM: #a3a3a3 1pt solid; BORDER-LEFT: #a3a3a3 1pt solid; PADDING-BOTTOM: 4pt; PADDING-LEFT: 4pt; WIDTH: 6.657in; PADDING-RIGHT: 4pt; VERTICAL-ALIGN: top; BORDER-TOP: #a3a3a3 1pt solid; BORDER-RIGHT: #a3a3a3 1pt solid; PADDING-TOP: 4pt">0-618-83096-0,Used*,$60.00,$74.95,183 In Stock,Textbook,Premium,$74.95,,"Out of Stock
</TD></TR><TR><TD style="BORDER-BOTTOM: #a3a3a3 1pt solid; BORDER-LEFT: #a3a3a3 1pt solid; PADDING-BOTTOM: 4pt; PADDING-LEFT: 4pt; WIDTH: 6.657in; PADDING-RIGHT: 4pt; VERTICAL-ALIGN: top; BORDER-TOP: #a3a3a3 1pt solid; BORDER-RIGHT: #a3a3a3 1pt solid; PADDING-TOP: 4pt">480 Premium Incoming - Available Shortly",Textbook,2,2011-05-23 09:28:01
</TD></TR><TR><TD style="BORDER-BOTTOM: #a3a3a3 1pt solid; BORDER-LEFT: #a3a3a3 1pt solid; PADDING-BOTTOM: 4pt; PADDING-LEFT: 4pt; WIDTH: 6.657in; PADDING-RIGHT: 4pt; VERTICAL-ALIGN: top; BORDER-TOP: #a3a3a3 1pt solid; BORDER-RIGHT: #a3a3a3 1pt solid; PADDING-TOP: 4pt">0-8359-5738-1,Used*,$36.35,$61.99,150 In Stock,Textbook,New,$55.79,$61.99,1-2 weeks,Textbook,2,2011-05-23 09:28:03
</TD></TR><TR><TD style="BORDER-BOTTOM: #a3a3a3 1pt solid; BORDER-LEFT: #a3a3a3 1pt solid; PADDING-BOTTOM: 4pt; PADDING-LEFT: 4pt; WIDTH: 6.657in; PADDING-RIGHT: 4pt; VERTICAL-ALIGN: top; BORDER-TOP: #a3a3a3 1pt solid; BORDER-RIGHT: #a3a3a3 1pt solid; PADDING-TOP: 4pt">0-07-619052-8,Used*,$48.50,$60.57,25 In Stock,Textbook,,,,,,1,2011-05-23 09:28:05
</TD></TR><TR><TD style="BORDER-BOTTOM: #a3a3a3 1pt solid; BORDER-LEFT: #a3a3a3 1pt solid; PADDING-BOTTOM: 4pt; PADDING-LEFT: 4pt; WIDTH: 6.657in; PADDING-RIGHT: 4pt; VERTICAL-ALIGN: top; BORDER-TOP: #a3a3a3 1pt solid; BORDER-RIGHT: #a3a3a3 1pt solid; PADDING-TOP: 4pt">0-07-874257-9,Used*,$57.15,$71.04,Out of Stock,Textbook,,,,,,1,2011-05-23 09:28:05
</TD></TR><TR><TD style="BORDER-BOTTOM: #a3a3a3 1pt solid; BORDER-LEFT: #a3a3a3 1pt solid; PADDING-BOTTOM: 4pt; PADDING-LEFT: 4pt; WIDTH: 6.657in; PADDING-RIGHT: 4pt; VERTICAL-ALIGN: top; BORDER-TOP: #a3a3a3 1pt solid; BORDER-RIGHT: #a3a3a3 1pt solid; PADDING-TOP: 4pt">0-87192-255-X,Used*,$0.99,$31.95,Out of Stock,Textbook,Used*,$9.49,$31.95,Out of Stock,Textbook,2,2011-05-23 09:28:08
</TD></TR><TR><TD style="BORDER-BOTTOM: #a3a3a3 1pt solid; BORDER-LEFT: #a3a3a3 1pt solid; PADDING-BOTTOM: 4pt; PADDING-LEFT: 4pt; WIDTH: 6.657in; PADDING-RIGHT: 4pt; VERTICAL-ALIGN: top; BORDER-TOP: #a3a3a3 1pt solid; BORDER-RIGHT: #a3a3a3 1pt solid; PADDING-TOP: 4pt">0-328-00667-X,Used*,$4.55,$6.17,Out of Stock,Workbook,Premium,$8.23,,"Out of Stock
</TD></TR><TR><TD style="BORDER-BOTTOM: #a3a3a3 1pt solid; BORDER-LEFT: #a3a3a3 1pt solid; PADDING-BOTTOM: 4pt; PADDING-LEFT: 4pt; WIDTH: 6.657in; PADDING-RIGHT: 4pt; VERTICAL-ALIGN: top; BORDER-TOP: #a3a3a3 1pt solid; BORDER-RIGHT: #a3a3a3 1pt solid; PADDING-TOP: 4pt">On Order",Workbook,2,2011-06-06 08:27:38
</TD></TR></TBODY></TABLE>


I need the column A to look like:

<TABLE style="BORDER-BOTTOM: #a3a3a3 1pt solid; BORDER-LEFT: #a3a3a3 1pt solid; BORDER-COLLAPSE: collapse; DIRECTION: ltr; BORDER-TOP: #a3a3a3 1pt solid; BORDER-RIGHT: #a3a3a3 1pt solid" border=1 cellSpacing=0 cellPadding=0 valign="top"><TBODY><TR><TD style="BORDER-BOTTOM: #a3a3a3 1pt solid; BORDER-LEFT: #a3a3a3 1pt solid; PADDING-BOTTOM: 4pt; PADDING-LEFT: 4pt; WIDTH: 6.657in; PADDING-RIGHT: 4pt; VERTICAL-ALIGN: top; BORDER-TOP: #a3a3a3 1pt solid; BORDER-RIGHT: #a3a3a3 1pt solid; PADDING-TOP: 4pt">0-618-56866-2,Used*,$68.25,$85.30,79 In Stock,Textbook,Premium,$85.30,,"358 In Stock 500+ Premium Incoming - Available Shortly",Textbook,2,2011-05-23 09:28:01
</TD></TR><TR><TD style="BORDER-BOTTOM: #a3a3a3 1pt solid; BORDER-LEFT: #a3a3a3 1pt solid; PADDING-BOTTOM: 4pt; PADDING-LEFT: 4pt; WIDTH: 6.657in; PADDING-RIGHT: 4pt; VERTICAL-ALIGN: top; BORDER-TOP: #a3a3a3 1pt solid; BORDER-RIGHT: #a3a3a3 1pt solid; PADDING-TOP: 4pt">0-618-83096-0,Used*,$60.00,$74.95,183 In Stock,Textbook,Premium,$74.95,,"Out of Stock
480 Premium Incoming - Available Shortly",Textbook,2,2011-05-23 09:28:01
</TD></TR><TR><TD style="BORDER-BOTTOM: #a3a3a3 1pt solid; BORDER-LEFT: #a3a3a3 1pt solid; PADDING-BOTTOM: 4pt; PADDING-LEFT: 4pt; WIDTH: 6.657in; PADDING-RIGHT: 4pt; VERTICAL-ALIGN: top; BORDER-TOP: #a3a3a3 1pt solid; BORDER-RIGHT: #a3a3a3 1pt solid; PADDING-TOP: 4pt">0-8359-5738-1,Used*,$36.35,$61.99,150 In Stock,Textbook,New,$55.79,$61.99,1-2 weeks,Textbook,2,2011-05-23 09:28:03
</TD></TR><TR><TD style="BORDER-BOTTOM: #a3a3a3 1pt solid; BORDER-LEFT: #a3a3a3 1pt solid; PADDING-BOTTOM: 4pt; PADDING-LEFT: 4pt; WIDTH: 6.657in; PADDING-RIGHT: 4pt; VERTICAL-ALIGN: top; BORDER-TOP: #a3a3a3 1pt solid; BORDER-RIGHT: #a3a3a3 1pt solid; PADDING-TOP: 4pt">0-07-619052-8,Used*,$48.50,$60.57,25 In Stock,Textbook,,,,,,1,2011-05-23 09:28:05
</TD></TR><TR><TD style="BORDER-BOTTOM: #a3a3a3 1pt solid; BORDER-LEFT: #a3a3a3 1pt solid; PADDING-BOTTOM: 4pt; PADDING-LEFT: 4pt; WIDTH: 6.657in; PADDING-RIGHT: 4pt; VERTICAL-ALIGN: top; BORDER-TOP: #a3a3a3 1pt solid; BORDER-RIGHT: #a3a3a3 1pt solid; PADDING-TOP: 4pt">0-07-874257-9,Used*,$57.15,$71.04,Out of Stock,Textbook,,,,,,1,2011-05-23 09:28:05
</TD></TR><TR><TD style="BORDER-BOTTOM: #a3a3a3 1pt solid; BORDER-LEFT: #a3a3a3 1pt solid; PADDING-BOTTOM: 4pt; PADDING-LEFT: 4pt; WIDTH: 6.657in; PADDING-RIGHT: 4pt; VERTICAL-ALIGN: top; BORDER-TOP: #a3a3a3 1pt solid; BORDER-RIGHT: #a3a3a3 1pt solid; PADDING-TOP: 4pt">0-87192-255-X,Used*,$0.99,$31.95,Out of Stock,Textbook,Used*,$9.49,$31.95,Out of Stock,Textbook,2,2011-05-23 09:28:08
</TD></TR><TR><TD style="BORDER-BOTTOM: #a3a3a3 1pt solid; BORDER-LEFT: #a3a3a3 1pt solid; PADDING-BOTTOM: 4pt; PADDING-LEFT: 4pt; WIDTH: 6.657in; PADDING-RIGHT: 4pt; VERTICAL-ALIGN: top; BORDER-TOP: #a3a3a3 1pt solid; BORDER-RIGHT: #a3a3a3 1pt solid; PADDING-TOP: 4pt">0-328-00667-X,Used*,$4.55,$6.17,Out of Stock,Workbook,Premium,$8.23,,"Out of Stock On Order",Workbook,2,2011-06-06 08:27:38
</TD></TR></TBODY></TABLE>

experts please help! thanks
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Looks like an import gone bad... might be easiest to re-do the import and fix whatever character is causing improper line breaks in your flat file first.

Otherwise, you could write a macro merge cells as you request. You're going to need some kind of rule. Is it true that a new line should always begin with "0-"? or any single digit nuber followed by a dash? This way, you can cause a cell from any row to be merged into the cell above it.

Is a merged cell what you really want? Supposing your first split is between rows 1 and 2, then a merge implies a single cell spanning the two rows. Or, do you want all the text combined into the first cell and the second cell deleted? Did you want to delete the whole spreadsheet row, or just the cell in column A? Did you want all the text combined into the second cell and the first row deleted instead? If you're relating this info to other cells in the sheet, this could make a big difference.
 
Upvote 0
Code:
 Is it true that a new line should always begin with "0-"? or any single digit nuber followed by a dash?

the first 7 characters should have "-" in them.

Code:
Is a merged cell what you really want? Supposing your first split is between rows 1 and 2, then a merge implies a single cell spanning the two rows. Or, do you want all the text combined into the first cell and the second cell deleted? Did you want to delete the whole spreadsheet row, or just the cell in column A? Did you want all the text combined into the second cell and the first row deleted instead?

all text combined into the 1st cell and 2nd cell deleted; delete the entire row
 
Upvote 0
Code:
Sub TextMerge()
    'Find the last cell in the column. (delete operations work best bottom to top)
    Cells(1, 1).Select
    Selection.End(xlDown).Select
    
    Dim i As Integer
    i = Selection.Row
    
    'Start iterating (bottom to top)
    For i = Selection.Row() To 1 Step -1
    
        'Test for a '-' in the first 7 characters of the row.
        If (Not (InStr(1, Left(Cells(i, 1).Value, 7), "-")) > 0) Then
            
            'If we don't find a '-', then concatenate this text to the end of the text in the cell above it...
            Cells(i - 1, 1).Value = Cells(i - 1, 1).Value & " " & Cells(i, 1).Value
            
            '... and then delete the current row
            Rows(i).Delete
            
        End If
    
    Next i
    
    
End Sub
 
Upvote 0
BTW -- since this has got a delete in a loop... PLEASE run it on a copy of your worksheet first, just in case.
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,291
Members
452,902
Latest member
Knuddeluff

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