View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
joel joel is offline
external usenet poster
 
Posts: 9,101
Default Insert cells based on duplicate entries

See if this macro works.. It assumes the left side is columns A - c and theh
Right side Columns D - F

Sub MakeNewRows()

RowCount = 1
Do While Range("A" & RowCount) < ""
If Range("B" & RowCount) < Range("E" & RowCount) Then
Rows(RowCount).Insert
Range("D" & (RowCount + 1) & ":F" & (RowCount + 1)).Cut _
Destination:=Range("A" & RowCount).Paste
RowCount = RowCount + 1
End If
If Range("B" & RowCount) = Range("B" & (RowCount + 1)) And _
Range("C" & RowCount) = Range("C" & (RowCount + 1)) Then


Range("A" & (RowCount + 1) & ":C" & (RowCount + 1)).Cut _
Destination:=Range("D" & RowCount).Paste
Rows(RowCount + 1).Delete
End If
RowCount = RowCount + 1
Loop


End Sub


"Versace77" wrote:

after reading my post it looks like the dollar amount from the right handside
is now under the date column on the left hand-side. it shouldn't be. it
should be on the right.

"Versace77" wrote:

Hey everyone, looking for some help and not sure if it's possible. I tried
checking other topics but couldn't find anything relative.

i have a spreadsheet that people paste data to on the left side, (columns
a,b and c). The fields are Date, Voucher number (all unique numbers) and
dollar amount. A query from a retrieval system populates this same data on
the right hand side with. However, on the right hand-side there may be two
'like' voucher numbers where the monetary total adds up to the one total on
the left side. When this occurs we need to insert cells and shift down on
the left hand side to keep all the voucher numbers in sequence by row.

Looking for a macro to do this for me as there can be more than 50 separate
insert cell, shift cell down actions taking place daily and it takes quite a
bit of time.

Here's a drawing of what i'm talking about.

Befo

02/17/09 VVDA123 $4,400.00 02/17/09 VVDA123 $4,000.00
02/17/09 VVDA155 $2,000.00 02/17/09 VVDA123 $400.00
02/17/09 VVDA200 $950.00 02/17/09 VVDA155 $2,000.00
02/17/09 VVDA200 $950.00

I want it to look like this:

02/17/09 VVDA123 $4,400.00 02/17/09 VVDA123 $4,000.00
02/17/09 VVDA123 $400.00
02/17/09 VVDA155 $2,000.00 02/17/09 VVDA155 $2,000.00
02/17/09 VVDA200 $950.00 02/17/09 VVDA200 $950.00

Hope this makes sense to someone out there. The spreadsheet is rather large
as daily data is appended. If the macro would be too slow running through
the entire sheet would it be possible to have the macro work just on selected
cells?

Thanks in advance for any help here.