View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Toppers Toppers is offline
external usenet poster
 
Posts: 4,339
Default Compare and align columns of data

Hi,

HTH. Assumes data starts in row 1; change initial value of i and j
as required.

Sub Transform()

Dim i As Long, j As Long

i = 1
j = 1

Do While (Cells(i, 1) < "") And (Cells(j, 3) < "")
If Cells(i, 1) Cells(j, 3) Then
Range(Cells(i, 1), Cells(i, 2)).Insert shift:=xlDown
Else
If Cells(i, 1) < Cells(j, 3) Then
Range(Cells(i, 3), Cells(i, 4)).Insert shift:=xlDown
End If
End If

i = i + 1
j = j + 1

Loop

End Sub



"JGouger" wrote:

I have two large files that I've combined into one sheet. They both list
account numbers and amounts charged. The account numbers could be the same
in both lists or could be in one list but not the other. I want to compare
the account numbers which would be in columns A & C. If they are the same I
want to move down and compare the next row. If the account number is in
column A but not column C I want to insert cells into C & D, then drop down
and compare the next row. If the account number is in C but not A I want to
insert cells into A&B and drop down to the next row and continue.

Before
A B C D
a/n
1 1.00 1 10.00
3 2.00 2 11.00
5 3.00 3 12.00
7 4.00 6 13.00

After
A B C D
1 1.00 1 10.00
2 11.00
3 2.00 3 12.00
5 3.00
6 13.00
7 4.00


I have never mastered the macro functions in Excel. I used to be able to do
this in Lotus. Any help would be appreaciated