Sorting Dates and Three Digit Codes

Papi

Well-known Member
Joined
May 22, 2007
Messages
1,592
Hello,

I have a couple of things that I am trying to do. Although the two worksheets work together I would like to clean them up as I am forcing columns to make it work as I failed to figure out how to put things together properly. For instance, I created column E to identify the month even though I am sure there is a way to look at the date from column B and do the same by collecting the data by each month in the YTD worksheet. (Excel 2010). One thing to mention is that the data in this sheet comes from a database and the dates are normally in TEXT format.

As well, I forced Column F to produce a three letter code to create a column that will show which supplier based on the first three digits of the account code which typically matches the first three letters of the Supplier Code. I figure there is a way to look at the Supplier Code and extract the first three digits but have been unable to do so.

Purchase Orders.xlsm
ABCDEF
1PONo.DateSupplierCodeTotalMMMSC
2103230May11EDM001708.71MayEDM
3105930May11MEDH001204.64MayMED
4190231Jul11MEDH001101.40JulMED
5195631Jul11REDD001162.90JulRED
6104625Jul11MEDH0011,875.06JulMED
7187704Jun11REDD001101.40JunRED
8127931May11EDM001129.08MayEDM
9139231Jul11GEN001129.08JulGEN
10109327Apr11REDD001464.25AprRED
11103115Aug11KIN00182.95AugKIN
12197615Aug11REDD001562.65AugRED
13193415Aug11GRE001562.65AugGRE
14198015Aug11MEDH001707.18AugMED
15201231Aug11REDD001255.15AugRED
Main


Purchase Orders.xlsm
ABCDEFG
1SupplierAprMayJunJulAugTotal
2EdmontonSteel 837.79   837.79
3MediCentre 204.64 1,976.46707.182,888.28
4RedRange464.25 101.40162.90817.801,546.35
5GeneralCity   129.08 129.08
6GreatWest    562.65562.65
7Kindle    82.9582.95
8Totals464.251,042.43101.402,268.442,170.586,047.10
YTD
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
In Column E you can use: =TEXT(DATEVALUE(B2),"mmm")
In Column F you can use: =LEFT(C2,3)

Edit: Or you can use just =DATEVALUE(B2) and then format the cells as "mmm" in the custom format. The benefit is that you can sort by the actual date while only displaying the month, or if you don't care about that you can use the first example.
 
Last edited:
Upvote 0
Witout columns E or F in Sheet 1, put the following formula in Sheet 2, Cell B2. Copy it to Cells B2 through F7.

Code:
=SUMPRODUCT(--(LEFT(Sheet1!$C$2:$C$15,3)=LEFT(UPPER(Sheet2!$A2),3)),--(MID(Sheet1!$B$2:$B$15,4,3)=TEXT(Sheet2!B$1,"mmm")),Sheet1!$D$2:$D$15)

As with your helper columns, this solution's logic has a problem if more than one Supplier has the same first three characters in their name.
 
Upvote 0
Witout columns E or F in Sheet 1, put the following formula in Sheet 2, Cell B2. Copy it to Cells B2 through F7.

Code:
=SUMPRODUCT(--(LEFT(Sheet1!$C$2:$C$15,3)=LEFT(UPPER(Sheet2!$A2),3)),--(MID(Sheet1!$B$2:$B$15,4,3)=TEXT(Sheet2!B$1,"mmm")),Sheet1!$D$2:$D$15)

As with your helper columns, this solution's logic has a problem if more than one Supplier has the same first three characters in their name.

I did not show the date correctly in sheet1 as it is entered 05/30/2011 (not 30 May 11) and yet the Text in row 1 of sheet2 is Text as it shows i.e. May Jun etc. I tried changing it to LEFT instead of MID but cannot seem to make it work. Sumproduct will likely work but the rows change daily and can be a matter of a few rows into several hundred rows. We can control the 3 digit supplier code as those codes are internal and the suppliers are few.
 
Upvote 0
One thing I noted was that if I press the F2 key and then press the enter key on each cell of Column B in sheet1 that the text date converts to an actual date and allows the first formula using sumifs to work. Is there a way that either a macro or some form of code could go into all of column B and change the dates from text into actual dates? The range could be a few rows or several hundred rows!
 
Upvote 0
This simple loop will do the trick.

Highlight the cells you want to change and execute the macro.

Code:
Sub DateChange()
For Each c In Selection
    If c.Value <> "" Then c.Value = DateValue(c.Value)
Next c
End Sub

Or specify a specific range if you don't want to bother with selecting.

Code:
Sub DateChange()
For Each c In Range("B2:B1000")
    If c.Value <> "" Then c.Value = DateValue(c.Value)
Next c
End Sub
 
Upvote 0
Change the formula for Cell B2 of Sheet 2 to the following, to account for the dates in sheet 1:

Code:
=SUMPRODUCT(--(LEFT(Sheet1!$C$2:$C$15,3)=LEFT(UPPER(Sheet2!$A2),3)),--(TEXT(Sheet1!$B$2:$B$15,"mmm")=Sheet2!B$1),Sheet1!$D$2:$D$15)
 
Upvote 0
Many thanks to both of you for your help on this matter. both of your ideas have been incorporated into not only this workbook, but a couple others as well.
 
Upvote 0

Forum statistics

Threads
1,224,537
Messages
6,179,405
Members
452,911
Latest member
a_barila

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