Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default Macro to merge text and delete rows

Hi

I have a list of text statements in Col A but it needs tidying up before I
can use it.

Basically I need a macro which scrolls down Col A and counts the commas. If
the comma count is 15 it moves on to the next cell but if it's 12 it cuts the
data from 2 rows below and adds it to the end of the current row. That will
make the comma count 15 as the data had been split but is now joined up.

Where there is initially a count of 12 the next row will always have zero
commas so I need to delete rows with no commas (including the rows that had 3
until the text was added to the end of the cell 2 rows up) so I finish with a
continuous list where the comma count is 15

I can count the commas with a formula
=(LEN(A1)-LEN(SUBSTITUTE(A1,",","")))/LEN(",") but I'm not sure how to put
this into a macro that will also cut and join text and delete the unwanted
rows.

Any help would be much appreciated

Thanks a lot

Kewa

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Macro to merge text and delete rows

Sub combinedrows()

LastRow = Range("A" & Rows.Count).End(xlUp).Row
RowCount = 1
Do While RowCount <= LastRow
Data = Range("A" & RowCount).Value
commarcount = 0
For i = 1 To Len(Data)
If Mid(Data, i, 1) = "," Then
commarcount = commarcount + 1
End If
Next i
If commarcount = 12 Then
Data = Data & Range("A" & (RowCount + 2)).Value
Range("A" & RowCount) = Data
Rows((RowCount + 1) & ":" & (RowCount + 2)).Delete
End If

RowCount = RowCount + 1
Loop

End Sub


"nospaminlich" wrote:

Hi

I have a list of text statements in Col A but it needs tidying up before I
can use it.

Basically I need a macro which scrolls down Col A and counts the commas. If
the comma count is 15 it moves on to the next cell but if it's 12 it cuts the
data from 2 rows below and adds it to the end of the current row. That will
make the comma count 15 as the data had been split but is now joined up.

Where there is initially a count of 12 the next row will always have zero
commas so I need to delete rows with no commas (including the rows that had 3
until the text was added to the end of the cell 2 rows up) so I finish with a
continuous list where the comma count is 15

I can count the commas with a formula
=(LEN(A1)-LEN(SUBSTITUTE(A1,",","")))/LEN(",") but I'm not sure how to put
this into a macro that will also cut and join text and delete the unwanted
rows.

Any help would be much appreciated

Thanks a lot

Kewa

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default Macro to merge text and delete rows

That's brilliant Joel - works perfectly. Thanks a lot

Kewa
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to calculate, merge, and delete Lost in Excel Excel Worksheet Functions 10 July 31st 09 04:56 PM
VBA macro to delete rows that contain text Rod from Corrections Excel Programming 2 January 25th 07 07:36 PM
Delete rows with numeric values, leave rows with text GSpline Excel Programming 5 October 11th 05 12:44 AM
Macro to Merge and Sum Rows MrGPeter Excel Programming 2 September 15th 05 09:35 AM
Macro to delete rows with text cells zsalleh Excel Programming 8 August 27th 04 12:22 AM


All times are GMT +1. The time now is 12:32 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"