VB code required to categorise bank payments

redspanna

Well-known Member
Joined
Jul 27, 2005
Messages
1,602
Office Version
  1. 365
Platform
  1. Windows
Hey all

Is there someone that can offer help with some VB code to do following task...

Here is some sample data from a banking statement

Book1
ABCD
101-Mar-22McDonalds15.47Take-Away
202-Mar-22Esso25Fuel
302-Mar-22ABC Council150Benefit
403-Mar-22Sainsburys135Grocery
504-Mar-22High Street Cinema25Activity
605-Mar-22Pockit10Gift
705-Mar-22BP Fuel10Fuel
806-Mar-22Iceland19Grocery
907-Mar-22Work1500Salary
1008-Mar-22State Tax35Benefit
Sheet1


Can the code look down each item in column B and give it a catagory in column D

For example if B1 holds something like Mcdonalds or Pizza Hut or Burger King or any other possible match that I could add, then the category Take Away is added to D1
further example is in B3 and B10 this item is recognised as a Benefit so that is added to D3 and D10

I will add all the possible category in the code but just need some help to get started - maybe something like....

If B1 equals to Mcdonalds,Pizza Hut, Burger King, Donkey , Sim Dong (plus others) then the category field for D1 would be Take Away
ELSE
If B1 equals to Shell, BP, ESSO, Total, First Garage (plus others) then the category field for D1 would be Fuel
ELSE
If B1 equals to ABC Council, Council ABC Payments, State Tax (plus others) then the category field for D1 would be Benefit

If no match found then leave D1 blank and move onto next cell in column B


Is this possible?? - any help much appreciated


thanks in advance
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
I would recommend creating a lookup table with all your possible values (that you currently show in column B) in one column, and the associated category in the next column.
Then you use a simple VLOOKUP formula to return the Category, kind of like what I am showing someone else in another thread right now (see: filling cell with a specific text if another cell contains any of the specific keywords).

The advantage to using a VLOOKUP (or XLOOKUP or INDEX/MATCH) formula over a long IF formula or VBA is it is dynamic, and you can easily add/remove items to your list without having to rewrite any formulas or VBA code each time.
 
Upvote 0
I would recommend creating a lookup table with all your possible values (that you currently show in column B) in one column, and the associated category in the next column.
Then you use a simple VLOOKUP formula to return the Category, kind of like what I am showing someone else in another thread right now (see: filling cell with a specific text if another cell contains any of the specific keywords).

The advantage to using a VLOOKUP (or XLOOKUP or INDEX/MATCH) formula over a long IF formula or VBA is it is dynamic, and you can easily add/remove items to your list without having to rewrite any formulas or VBA code each time.
Thanks @Joe4 , I was thinking along those lines as I was waiting for a reply here!
I apprecite your advive and I'll check out your other post to help along the way

Many thanks
 
Upvote 0
The above is prob the best solution but if you wanted to go the formula route you could use (obvioulsy you need to add all catergories) and the down side is that if the categories change you need to alter the formula each time
Excel Formula:
=IF(OR(B1={"McDonalds","Pizza Hut"}),"Take Away",IF(OR(B1={"Shell","BP"}),"Fuel",IF(OR(B1={"ABC Council","State Tax"}),"Benefit","")))
 
Upvote 0
The above is prob the best solution but if you wanted to go the formula route you could use (obvioulsy you need to add all catergories) and the down side is that if the categories change you need to alter the formula each time
Excel Formula:
=IF(OR(B1={"McDonalds","Pizza Hut"}),"Take Away",IF(OR(B1={"Shell","BP"}),"Fuel",IF(OR(B1={"ABC Council","State Tax"}),"Benefit","")))
Thanks @gordsky
 
Upvote 0
Yeah, the "nature of the beast" suggests that you will probably need to be adding records quite a bit, as it appears to be a bank or credit card statement, and there is no limit to the number of different merchants you may use it at.

So I would strongly consider a solution that allows you to easily add more records without having to rewrite a bunch of formulas or code.
 
Upvote 0

Forum statistics

Threads
1,215,064
Messages
6,122,936
Members
449,094
Latest member
teemeren

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