Question

Let's say there is a report to compare charges with adjustments that outputs to excel, such that each row has the following fields:

  • Account Number
  • charge date
  • Original item number
  • Adjusted Item number
  • Original Qty
  • Adjusted Qty
  • Original amount
  • Adjusted amount
  • Original Post date
  • Adjusted Post date

I need to help a user create a view in Excel that helps them spot changes in each record. She wants it to show each record in two rows like this:

Account  |  Date  |  O. Item  |  O. Qty  |  O. Amount  |  O. Post
         |        |  A. Item  |  A. Qty  |  A. Amount  |  A. Post             

Is there anything built into Excel to allow you to group records like this? VBA is not an option in this case.

It's okay if the cells under account and date duplicate those values, if that makes it easier. Bonus points if you can get some kind of alternating row effect that helps delimit each record (that part I can do on my own in vba later if I have to).

Was it helpful?

Solution

It is a little tricky, but doable. I'm looking into this currently, stand by.

Okay, the idea is this.

You have the following layout:

/|    A    |    B    |    C    |    D    |    F    |
-+---------+---------+---------+---------+---------+
1| Acc No. |  Data1  |  Data1' |  Data2  |  Data2' |
2|       1 |      10 |      11 |    a    |    b    |
3|       2 |     100 |     108 |    a    |    a    |
4|       3 |      50 |      55 |    f    |    g    |

Make a second Sheet:

/|  A  |  B  |    C                        |    D                        |
-+-----+-----+-----------------------------+-----------------------------+
1| A/O | Ref |  Data1                      |  Data2                      |
2|   A |   2 | =INDIRECT("Sheet1!B" & $B2) | =INDIRECT("Sheet1!D" & $B2) |
3|   O |   2 | =INDIRECT("Sheet1!C" & $B3) | =INDIRECT("Sheet1!E" & $B3) |
4|   A |   3 | =INDIRECT("Sheet1!B" & $B4) | =INDIRECT("Sheet1!D" & $B4) |
5|   O |   3 | =INDIRECT("Sheet1!C" & $B5) | =INDIRECT("Sheet1!E" & $B5) |

Columns "A/0" and "Ref" are manual, in my current model. Probably there is a way to automate them but I wanted to keep it simple. Filling down to cover an arbitrarily long input table in Sheet1 would work.

OTHER TIPS

A simple workaround might be to use Conditional Formatting (directions are for Office 2007):

  1. Highlight the "Adjusted" column (suppose, it's Column D and the Original was column C)
  2. Click "Conditional Formatting"
  3. Click "New Rule..."
  4. Click the last item "Usa a formula to determine which cells to format"
  5. Enter C1 <> D1
  6. Pick a formatting style.

Apply the rule, and all the entries that don't match will be highlighted in the style you selected.

I also did this with Indirect. My formulas on the second sheet look something like:

=INDIRECT("source!A" & INT(ROW()/2)+1)

You will hard-code the letter to indicate the column source, and then the calculation will automatically choose from the correct row. Should copy down as far as you need.

I think it is only possible with programming (hey, this is a programming-related site).

When VBA is not an option, is it allowed to use VB.Net or C#?

Conditional formatting can do both jobs, because you can have up to 3 conditions per cell

  1. you can (say) use red bold text to highlight any cells which are different, using a validation formula like this

    eg =(DataA!C8 <> DataB!C8)

  2. you can shade alternate rows using a formula like this (as used in cell C8)

    eg =(MOD(CELL("Row",C8),2)=0)

which will shade even rows. To shade odd rows instead, of course, use =1 at the end of the formula instead of =0

I've done exactly this in VBA a few years ago and it worked great, i guess you could do the samething using C# with Interops?

I could tell what was added, removed and changed. It create a report in the end which was easy to sort out and filter.

Is there a reason why VBA is not an option? And what other options are available?

you could also cross reference the data using Excel functions, but this can be quite complicated for someone who is not an excel power user. general help in excel formulas

Edit: you will need functions like Find Index Offset VLookup Match, this can all be done by combining them. the only drawback is that there is a limit to the formula length. When this limit is reached split the logic in multiple columns or rows.

Edit: you could intergrate the VBA in a single workbook, and have the template saved. each time they wish to compare they use this template to execute the comparisson. this way no deployment is required. they simply need to copy the file and use it.

Edit: The solution proposed by Tomalak may not work since when records are added or removed, we have no control on where these records will be positioned. you will need to find the row with a key match and work from there.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top