Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default Help with some code that Martin wrote

Martin wrote this code a while back and I'm trying to manipulate it so
that it returns the highest value in column 4 only, not a concatenation
of all the values in column 4.

Basically the code does this:

Input:
A B C D
Europe Germany Name1 Frankfurt
Europe Germany Name1 Munich
Europe France Name2 Paris
Asia Japan Name3 Tokyo
Asia Japan Name3 Osaka

Output:
A B C D
Europe Germany Name1 Frankfurt, Munich
Europe France Name2 Paris
Asia Japan Name3 Tokyo, Osaka

Here's the code:

Option Explicit

Sub concat()

Dim lRowFirst As Long
Dim lRowLast As Long
Dim lRow As Long
lRowFirst = ActiveCell.CurrentRegion.Row + 1
lRowLast = ActiveCell.CurrentRegion.Rows.Count + lRowFirst - 2

For lRow = lRowLast To lRowFirst Step -1
If Cells(lRow, 1) = Cells(lRow - 1, 1) And _
Cells(lRow, 2) = Cells(lRow - 1, 2) And _
Cells(lRow, 3) = Cells(lRow - 1, 3) Then
Cells(lRow - 1, 4) = Cells(lRow - 1, 4) _
& ", " & Cells(lRow, 4)
Rows(lRow).Delete
End If
Next lRow

End Sub

Thank You,
-- Dan

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,726
Default Help with some code that Martin wrote

Sub concat()
Dim lRowFirst As Long
Dim lRowLast As Long
Dim lLastCol As Long
Dim lRow As Long
lRowFirst = ActiveCell.CurrentRegion.Row + 1
lRowLast = ActiveCell.CurrentRegion.Rows.Count + lRowFirst - 2

For lRow = lRowLast To lRowFirst Step -1
If Cells(lRow, 1) = Cells(lRow - 1, 1) And _
Cells(lRow, 2) = Cells(lRow - 1, 2) And _
Cells(lRow, 3) = Cells(lRow - 1, 3) Then
lLastCol = Cells(lRow, Columns.Count).End(xlToLeft).Column
Cells(lRow, 4).Resize(, lLastCol - 3).Copy Cells(lRow - 1, 5)
Rows(lRow).Delete
End If
Next lRow

End Sub

--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"Dan R." wrote in message
ps.com...
Martin wrote this code a while back and I'm trying to manipulate it so
that it returns the highest value in column 4 only, not a concatenation
of all the values in column 4.

Basically the code does this:

Input:
A B C D
Europe Germany Name1 Frankfurt
Europe Germany Name1 Munich
Europe France Name2 Paris
Asia Japan Name3 Tokyo
Asia Japan Name3 Osaka

Output:
A B C D
Europe Germany Name1 Frankfurt, Munich
Europe France Name2 Paris
Asia Japan Name3 Tokyo, Osaka

Here's the code:

Option Explicit

Sub concat()

Dim lRowFirst As Long
Dim lRowLast As Long
Dim lRow As Long
lRowFirst = ActiveCell.CurrentRegion.Row + 1
lRowLast = ActiveCell.CurrentRegion.Rows.Count + lRowFirst - 2

For lRow = lRowLast To lRowFirst Step -1
If Cells(lRow, 1) = Cells(lRow - 1, 1) And _
Cells(lRow, 2) = Cells(lRow - 1, 2) And _
Cells(lRow, 3) = Cells(lRow - 1, 3) Then
Cells(lRow - 1, 4) = Cells(lRow - 1, 4) _
& ", " & Cells(lRow, 4)
Rows(lRow).Delete
End If
Next lRow

End Sub

Thank You,
-- Dan



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 220
Default Help with some code that Martin wrote

Perfect, thanks Bob.

Bob Phillips wrote:
Sub concat()
Dim lRowFirst As Long
Dim lRowLast As Long
Dim lLastCol As Long
Dim lRow As Long
lRowFirst = ActiveCell.CurrentRegion.Row + 1
lRowLast = ActiveCell.CurrentRegion.Rows.Count + lRowFirst - 2

For lRow = lRowLast To lRowFirst Step -1
If Cells(lRow, 1) = Cells(lRow - 1, 1) And _
Cells(lRow, 2) = Cells(lRow - 1, 2) And _
Cells(lRow, 3) = Cells(lRow - 1, 3) Then
lLastCol = Cells(lRow, Columns.Count).End(xlToLeft).Column
Cells(lRow, 4).Resize(, lLastCol - 3).Copy Cells(lRow - 1, 5)
Rows(lRow).Delete
End If
Next lRow

End Sub

--
---
HTH

Bob

(change the xxxx to gmail if mailing direct)


"Dan R." wrote in message
ps.com...
Martin wrote this code a while back and I'm trying to manipulate it so
that it returns the highest value in column 4 only, not a concatenation
of all the values in column 4.

Basically the code does this:

Input:
A B C D
Europe Germany Name1 Frankfurt
Europe Germany Name1 Munich
Europe France Name2 Paris
Asia Japan Name3 Tokyo
Asia Japan Name3 Osaka

Output:
A B C D
Europe Germany Name1 Frankfurt, Munich
Europe France Name2 Paris
Asia Japan Name3 Tokyo, Osaka

Here's the code:

Option Explicit

Sub concat()

Dim lRowFirst As Long
Dim lRowLast As Long
Dim lRow As Long
lRowFirst = ActiveCell.CurrentRegion.Row + 1
lRowLast = ActiveCell.CurrentRegion.Rows.Count + lRowFirst - 2

For lRow = lRowLast To lRowFirst Step -1
If Cells(lRow, 1) = Cells(lRow - 1, 1) And _
Cells(lRow, 2) = Cells(lRow - 1, 2) And _
Cells(lRow, 3) = Cells(lRow - 1, 3) Then
Cells(lRow - 1, 4) = Cells(lRow - 1, 4) _
& ", " & Cells(lRow, 4)
Rows(lRow).Delete
End If
Next lRow

End Sub

Thank You,
-- Dan


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
To: Martin vov Gagern Speed uUp Excel 2007 Startup robert morris Excel Discussion (Misc queries) 0 August 19th 07 05:16 AM
who origonally wrote the workbook? Todd Excel Programming 4 March 1st 06 10:43 PM
How do I find out what time I wrote A letter? Dawn M. Boysen Excel Discussion (Misc queries) 1 January 31st 06 01:50 AM
Miss-wrote previous "IF" problem gbeard Excel Worksheet Functions 3 April 14th 05 11:27 PM
My (old) function that I wrote doesn't work anymore! Jimmy Excel Programming 1 July 26th 03 08:42 AM


All times are GMT +1. The time now is 04:34 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"