Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Merging rows based on column value


I have an interesting problem. I have the data in the following
format:

a1|b1|c1|d1|__|__|
a1|b1|__|__|e1|f1|
a2|b2|c2|d2|__|__|
a2|b2|__|__|e2|f2|


and I'd like to be able to merge the rows based on the values in the
first two columns. So the above table would become:

a1|b1|c1|d1|e1|f1|
a2|b2|c2|d2|e2|f2|

I have a large file in this format, where I must merge 2,3 or
sometimes 4 rows in this fashion.

Anyone ?

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Merging rows based on column value

So the row with the higher number overlays the previous row--but only if that
value isn't blank, right?

If yes:

Option Explicit
Sub testme()

Dim iRow As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim iCol As Long

Dim wks As Worksheet

Set wks = Worksheets("Sheet1")
With wks
FirstRow = 1
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For iRow = LastRow To FirstRow + 1 Step -1
If .Cells(iRow, "A").Value = .Cells(iRow - 1, "A").Value _
And .Cells(iRow, "B").Value = .Cells(iRow - 1, "B").Value Then
'both match, do some merging
For iCol = 3 To _
.Cells(iRow, .Columns.Count).End(xlToLeft).Column
If .Cells(iRow, iCol).Value = "" Then
'skip it
Else
'move the value up a row
.Cells(iRow - 1, iCol).Value _
= .Cells(iRow, iCol).Value
End If
Next iCol
'delete that row
.Rows(iRow).Delete
End If
Next iRow
End With

End Sub

wrote:

I have an interesting problem. I have the data in the following
format:

a1|b1|c1|d1|__|__|
a1|b1|__|__|e1|f1|
a2|b2|c2|d2|__|__|
a2|b2|__|__|e2|f2|

and I'd like to be able to merge the rows based on the values in the
first two columns. So the above table would become:

a1|b1|c1|d1|e1|f1|
a2|b2|c2|d2|e2|f2|

I have a large file in this format, where I must merge 2,3 or
sometimes 4 rows in this fashion.

Anyone ?


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 1
Default Merging rows based on column value

On Nov 14, 4:25 pm, Dave Peterson wrote:
So the row with the higher number overlays the previous row--but only if that
value isn't blank, right?

If yes:

Option Explicit
Sub testme()

Dim iRow As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim iCol As Long

Dim wks As Worksheet

Set wks = Worksheets("Sheet1")
With wks
FirstRow = 1
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For iRow = LastRow To FirstRow + 1 Step -1
If .Cells(iRow, "A").Value = .Cells(iRow - 1, "A").Value _
And .Cells(iRow, "B").Value = .Cells(iRow - 1, "B").Value Then
'both match, do some merging
For iCol = 3 To _
.Cells(iRow, .Columns.Count).End(xlToLeft).Column
If .Cells(iRow, iCol).Value = "" Then
'skip it
Else
'move the value up a row
.Cells(iRow - 1, iCol).Value _
= .Cells(iRow, iCol).Value
End If
Next iCol
'delete that row
.Rows(iRow).Delete
End If
Next iRow
End With

End Sub



wrote:

I have an interesting problem. I have the data in the following
format:


a1|b1|c1|d1|__|__|
a1|b1|__|__|e1|f1|
a2|b2|c2|d2|__|__|
a2|b2|__|__|e2|f2|


and I'd like to be able to merge the rows based on the values in the
first two columns. So the above table would become:


a1|b1|c1|d1|e1|f1|
a2|b2|c2|d2|e2|f2|


I have a large file in this format, where I must merge 2,3 or
sometimes 4 rows in this fashion.


Anyone ?


--

Dave Peterson


Worked like a charm. Thank you

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
Deleting Rows based on Column Critieria blackmanofsteel40 Excel Discussion (Misc queries) 1 September 7th 07 09:05 PM
Countings rows based on column criteria Steve Excel Discussion (Misc queries) 2 April 19th 07 09:31 AM
how do i omit rows for printing based on column value haloprod Excel Discussion (Misc queries) 1 April 5th 06 04:59 AM
Summing rows based on column headings DallasLDY Excel Worksheet Functions 1 March 8th 06 09:35 PM
Need to select rows to average based on a value in a different column Randy K New Users to Excel 1 February 15th 06 01:03 AM


All times are GMT +1. The time now is 07:23 AM.

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"