Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Combine like rows

Hi -
In my data, there are 5 columns, CAR, TRUCK, NAME, CITY, STATE. The first
two columns will have a X in it if the person has a CAR or TRUCK. With the
data I am pulling from, if the same person has both a Car and Truck, they
will show up twice in seperate rows. I would like to find when a person has
both and combine it to one row (with a X in each CAR and TRUCK). So from:

CAR TRUCK NAME CITY STATE
X Mike Orlando FL
X Mike Orlando FL

To:

CAR TRUCK NAME CITY STATE
X X Mike Orlando FL

Help please...I am stuck.
Thanks,
Mike
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Combine like rows

Sub combinerows()

Const CarCol = "A"
Const TruckCol = "B"
Const NameCol = "C"
Const CityCol = "D"
Const StateCol = "E"

RowCount = 2
Do While Not IsEmpty(Cells(RowCount + 1, NameCol))
If Cells(RowCount, NameCol) = _
Cells(RowCount + 1, NameCol) And _
Cells(RowCount, CityCol) = _
Cells(RowCount + 1, CityCol) And _
Cells(RowCount, StateCol) = _
Cells(RowCount + 1, StateCol) Then

If IsEmpty(Cells(RowCount, CarCol)) Then
Cells(RowCount, CarCol) = _
Cells(RowCount + 1, CarCol)
End If
If IsEmpty(Cells(RowCount, TruckCol)) Then
Cells(RowCount, TruckCol) = _
Cells(RowCount + 1, TruckCol)
End If

Cells(RowCount + 1, "A").EntireRow.Delete
End If

RowCount = RowCount + 1
Loop

End Sub


"Mike R." wrote:

Hi -
In my data, there are 5 columns, CAR, TRUCK, NAME, CITY, STATE. The first
two columns will have a X in it if the person has a CAR or TRUCK. With the
data I am pulling from, if the same person has both a Car and Truck, they
will show up twice in seperate rows. I would like to find when a person has
both and combine it to one row (with a X in each CAR and TRUCK). So from:

CAR TRUCK NAME CITY STATE
X Mike Orlando FL
X Mike Orlando FL

To:

CAR TRUCK NAME CITY STATE
X X Mike Orlando FL

Help please...I am stuck.
Thanks,
Mike

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Combine like rows

Hi - thanks for the reply. For some reason, this does not seem to work.
More help please. I really appreciate it.
Mike

"Joel" wrote:

Sub combinerows()

Const CarCol = "A"
Const TruckCol = "B"
Const NameCol = "C"
Const CityCol = "D"
Const StateCol = "E"

RowCount = 2
Do While Not IsEmpty(Cells(RowCount + 1, NameCol))
If Cells(RowCount, NameCol) = _
Cells(RowCount + 1, NameCol) And _
Cells(RowCount, CityCol) = _
Cells(RowCount + 1, CityCol) And _
Cells(RowCount, StateCol) = _
Cells(RowCount + 1, StateCol) Then

If IsEmpty(Cells(RowCount, CarCol)) Then
Cells(RowCount, CarCol) = _
Cells(RowCount + 1, CarCol)
End If
If IsEmpty(Cells(RowCount, TruckCol)) Then
Cells(RowCount, TruckCol) = _
Cells(RowCount + 1, TruckCol)
End If

Cells(RowCount + 1, "A").EntireRow.Delete
End If

RowCount = RowCount + 1
Loop

End Sub


"Mike R." wrote:

Hi -
In my data, there are 5 columns, CAR, TRUCK, NAME, CITY, STATE. The first
two columns will have a X in it if the person has a CAR or TRUCK. With the
data I am pulling from, if the same person has both a Car and Truck, they
will show up twice in seperate rows. I would like to find when a person has
both and combine it to one row (with a X in each CAR and TRUCK). So from:

CAR TRUCK NAME CITY STATE
X Mike Orlando FL
X Mike Orlando FL

To:

CAR TRUCK NAME CITY STATE
X X Mike Orlando FL

Help please...I am stuck.
Thanks,
Mike

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Combine like rows

Hi - I have figured it out. The code works when I sort by name. Thanks!
Mike

"Mike R." wrote:

Hi - thanks for the reply. For some reason, this does not seem to work.
More help please. I really appreciate it.
Mike

"Joel" wrote:

Sub combinerows()

Const CarCol = "A"
Const TruckCol = "B"
Const NameCol = "C"
Const CityCol = "D"
Const StateCol = "E"

RowCount = 2
Do While Not IsEmpty(Cells(RowCount + 1, NameCol))
If Cells(RowCount, NameCol) = _
Cells(RowCount + 1, NameCol) And _
Cells(RowCount, CityCol) = _
Cells(RowCount + 1, CityCol) And _
Cells(RowCount, StateCol) = _
Cells(RowCount + 1, StateCol) Then

If IsEmpty(Cells(RowCount, CarCol)) Then
Cells(RowCount, CarCol) = _
Cells(RowCount + 1, CarCol)
End If
If IsEmpty(Cells(RowCount, TruckCol)) Then
Cells(RowCount, TruckCol) = _
Cells(RowCount + 1, TruckCol)
End If

Cells(RowCount + 1, "A").EntireRow.Delete
End If

RowCount = RowCount + 1
Loop

End Sub


"Mike R." wrote:

Hi -
In my data, there are 5 columns, CAR, TRUCK, NAME, CITY, STATE. The first
two columns will have a X in it if the person has a CAR or TRUCK. With the
data I am pulling from, if the same person has both a Car and Truck, they
will show up twice in seperate rows. I would like to find when a person has
both and combine it to one row (with a X in each CAR and TRUCK). So from:

CAR TRUCK NAME CITY STATE
X Mike Orlando FL
X Mike Orlando FL

To:

CAR TRUCK NAME CITY STATE
X X Mike Orlando FL

Help please...I am stuck.
Thanks,
Mike

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
Combine rows and Qty jml2008 Excel Discussion (Misc queries) 1 April 12th 10 07:24 PM
How to combine rows? Dina Excel Discussion (Misc queries) 4 March 5th 10 08:35 AM
How do I combine worksheets w/o enough rows to combine? Amanda W. Excel Worksheet Functions 3 June 9th 09 07:26 AM
Combine rows beanmonger Excel Discussion (Misc queries) 3 October 11th 05 10:34 AM
how to combine the multiple rows into one rows? Rusy Excel Worksheet Functions 0 July 19th 05 02:45 PM


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

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

About Us

"It's about Microsoft Excel"