PC Review


Reply
Thread Tools Rate Thread

Automatically Combining Entries with Same Date

 
 
ritland@gmail.com
Guest
Posts: n/a
 
      2nd Oct 2007
I currently log costs for our clients into an excel database. Each
client has their own worksheet which contains the following columns:

Date (A) - Postage (B) - Copies (C) - Fax (D) - Phone (E)

I am given cost sheets to input into the database that are not in
chronological order nor grouped by type. As a result, after I input
the information I find that there are often multiple entries for one
day and often more than one entry per category per day. For instance,
I will have rows 1, 5, and 10 with the same date but with different
costs in each ( R1 - $.40 Postage, R5 - $1.00 Copies, R10 $.30
Postage). What I would like to do is create a VB script that would
automatically run when each worksheet is selected that would do the
following:
(1) Find rows with the same date
(2) Combine the information from the matching rows into one entry (1B
+5B+10B, 1C+5C+10C, ect)
(3) Delete all rows with that date except for the summarized row

I am sure this is possible, but I lack the VB experience to create it.
I assume it will have to loop through an array but I dont know how it
would be set up. Any thoughts or know of any code that would do
something similar that I could modify? Thanks for all your help.

 
Reply With Quote
 
 
 
 
Ken Johnson
Guest
Posts: n/a
 
      3rd Oct 2007
On Oct 3, 3:36 am, ritl...@gmail.com wrote:
> I currently log costs for our clients into an excel database. Each
> client has their own worksheet which contains the following columns:
>
> Date (A) - Postage (B) - Copies (C) - Fax (D) - Phone (E)
>
> I am given cost sheets to input into the database that are not in
> chronological order nor grouped by type. As a result, after I input
> the information I find that there are often multiple entries for one
> day and often more than one entry per category per day. For instance,
> I will have rows 1, 5, and 10 with the same date but with different
> costs in each ( R1 - $.40 Postage, R5 - $1.00 Copies, R10 $.30
> Postage). What I would like to do is create a VB script that would
> automatically run when each worksheet is selected that would do the
> following:
> (1) Find rows with the same date
> (2) Combine the information from the matching rows into one entry (1B
> +5B+10B, 1C+5C+10C, ect)
> (3) Delete all rows with that date except for the summarized row
>
> I am sure this is possible, but I lack the VB experience to create it.
> I assume it will have to loop through an array but I dont know how it
> would be set up. Any thoughts or know of any code that would do
> something similar that I could modify? Thanks for all your help.



Try this macro out on a copy of one of your worksheets...

Option Explicit
Public Sub MERGE_SAME_COL_A_DATES()
Application.ScreenUpdating = False
Dim lnLastRow As Long
Dim I As Long
Dim J As Long
Dim K As Long
lnLastRow = Cells(Rows.Count, 1).End(xlUp).Row
'Start from top of rows with dates
'If headings are more than 1 row deep
'change the 2 to number of heading rows + 1
For I = 2 To lnLastRow
'Compare with rows from bottom of sheet
'If headings are more than 1 row deep
'change the 3 to number of heading rows + 2
For J = lnLastRow To 3 Step -1
'Don't compare same row
If J = I Then Exit For
'Test dates
If Cells(I, 1).Value = Cells(J, 1).Value Then
'Date are the same
'Add postage,copies,fax and phone values
For K = 2 To 5
Cells(I, K).Value = Cells(I, K).Value + _
Cells(J, K).Value
Next K
'Delete the lower row
Cells(J, 1).EntireRow.Delete
'Deleted row reduces lnLastRow by 1
lnLastRow = lnLastRow - 1
End If
'Compare next row up with the same upper row
Next J
'Test next upper row down
Next I
End Sub

Ken Johnson

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Combining multiple entries stetka Microsoft Excel Charting 0 7th Aug 2009 04:16 PM
combining multiple entries into one result =?Utf-8?B?c3dqdW5raWU=?= Microsoft Access Queries 6 26th Sep 2007 06:48 PM
Automatically inserting entries based on a calendar date nirmeet@gmail.com Microsoft Access 4 9th May 2007 03:03 PM
Combining Two Range of Entries into One JaGGeR Microsoft Excel Misc 4 17th Nov 2003 04:11 PM
combining cell entries rjz@haaghuishof.nl Microsoft Excel Discussion 1 4th Jul 2003 03:35 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:06 AM.