How to arrange a data range into a new table based on multiple criteria?

Tantalus

New Member
Joined
Aug 27, 2012
Messages
7
Hi all,

I have a problem whereby I have a list of data that has a date, a transaction and a balance. I want to be able to rearrange this data into multiple tables, one for each month.

The pictures below explain the situation better, on the left is the list of data I need to sort, and on the right is how I'd like the data displayed. So for the May columns I would like to display all transactions that happened in May and, depending on whether it is an income or an expense, the amount in the corresponding column.

Pic_1.jpg




i.e. so the finish result looks something like this:
Pic_2.jpg


Any help would be much appreciated
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Hi and welcome to the forum,

Perhaps try using a PivotTable. One way might be:

  • Add an extra column to the end of your dataset called 'Type' like this (dragging down the formula in D2):

    Sheet1
    ABCD
    1DateItemAmountType
    202-MayRent-300Expense
    304-MayPhone Bill-25Expense
    410-MayCar Insurance-30Expense
    515-MayTV Sale200Income
    621-MaySalary1234Income
    728-MayFood Shop-45Expense
    804-JunRent-300Expense
    910-JunElectricity Bill-12Expense
    1015-JunWater Bill-5Expense
    1122-JunFood Shop-28.43Expense
    1223-JunSalary1234Income

    <tbody>
    </tbody>
    Excel 2010

    Worksheet Formulas
    CellFormula
    D2=IF(SIGN(C2)=1,"Income","Expense")

    <tbody>
    </tbody>

    <tbody>
    </tbody>
  • Select the whole range of data (including the column headers) and insert a PivotTable
  • Drag Date into the Column Labels
  • Drag Type into the Column Labels
  • Drag Item into the Row Labels
  • Drag Amount into the Values area
  • Select the first date in the Column Labels, choose Group Field and select Months
  • Remove SubTotals
Note that this won't be exactly as you wanted as the row labels are only displayed once on the left. Filtering by month will then give you just the items for each month.
 
Upvote 0
Is there a particular reason you want to avoid PivotTables?

Well mainly for my own asthetic reasons, but also it makes it easier for other calculations using the data and that the sheet will need to be used with older versions of excel (and i'm not sure if pivot tables would work?)

Plus I do like a good formula...
 
Upvote 0
Well mainly for my own asthetic reasons, but also it makes it easier for other calculations using the data and that the sheet will need to be used with older versions of excel (and i'm not sure if pivot tables would work?)

Plus I do like a good formula...
Ok, hopefully someone can help with a formula solution.

In case it helps in the future and you haven't already used PivotTables much before, here are some resources you might find useful on learning about them. They are very easy, flexible and useful in many situations. I think they should be compatible with older versions of Excel (not sure how far back, although at least 2002):

Office 2010 Class #36: Excel PivotTables Pivot Tables 15 examples (Data Analysis) - YouTube
Excel Pivot Tables Tutorial : What is a Pivot Table and How to Make one | Chandoo.org - Learn Microsoft Excel Online
Excel Pivot Table -- Dynamic Data Source
 
Upvote 0
Code:
Sub a()
LR = Cells(Rows.Count, "A").End(xlUp).Row
DR = 3
Dcol = 5
prevmonth = 5
For j = 2 To LR
  Item = Cells(j, 2).Value
  amount = Cells(j, 3).Value
  amonth = Month(Cells(j, 1).Value)
  If amonth = prevmonth + 1 Then
    DR = 3
    prevmonth = amonth
  End If
  If amount >= 0 Then
    col = 0
  Else
    col = 1
  End If
  Cells(DR, Dcol + (amonth - 5) * 3).Value = Item
  Cells(DR, Dcol + (amonth - 5) * 3 + 1 + col).Value = Abs(amount)
  DR = DR + 1
Next
End Sub
 
Upvote 0
Here's a possible formula approach. I've used columns D & E as helper columns.

Formula in D2 is copied down.
Column E is is populated manually.
Formulas in F3:H3 copied down. Then F3:H?? can be copied and pasted to I3, L3 etc

Excel Workbook
ABCDEFGHIJKLMN
1DateItemAmountMayJuneJuly
202-May-12Item 1-300May1ItemIncomeExpenseItemIncomeExpenseItemIncomeExpense
304-May-12Item 225May21Item 1 300Item 2301Item 31.86
410-May-12Item 380May32Item 225Item 325Item 423.28
515-May-12Item 4-2May43Item 380Item 7200Item 516
621-May-12Item 5-352May54Item 42Item 850
728-May-12Item 633May65Item 5352Item 1247
804-Jun-12Item 2301June16Item 633
910-Jun-12Item 325June27
1015-Jun-12Item 7-200June38
1122-Jun-12Item 8-50June49
1223-Jun-12Item 1247June510
1303-Jul-12Item 31.86July111
1409-Jul-12Item 4-23.28July212
1514-Jul-12Item 516July313
16
Tables
 
Upvote 0
Thank you for all your replies, you've all been really helpful. I decided to use your method Peter as it best fits what I wanted to achieve, and it's safe to say that it would've taken me a considerable amount of effort and time to come up with that so thanks :P.
 
Upvote 0

Forum statistics

Threads
1,214,390
Messages
6,119,235
Members
448,879
Latest member
VanGirl

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top