Excel as a Database

rigeljr

New Member
Joined
Jul 5, 2021
Messages
17
Office Version
  1. 365
Platform
  1. Windows
Hi there,

I'm not even sure how to title this question properly and I think it is best demonstrated with an image. I'm not sure if this can be done but I would certainly like to try.

We have entries for various units (2026 is just an example). I would like to conditionally format the cells so that for each unit, if the following conditions are met, the cells get highlighted:
- If a "New" is followed by a "New" for the same unit
- If an "Expire" is followed by an "Expire" for the same unit
- If an "Expire" is followed by a "Renew" for the same unit
- If a "Renew" is followed by a "New" for the same unit

1625512712838.png


Happy to clarify the problem if necessary but would really appreciate any help with this.

Thank you!
 
If it would help you check the results then you can add another column "Previous Row" which formula gives the row number of the previous Start Date for this unit.

Rigeljr.xlsx
BCDEFGHIJKL
1Start_DateRecordedLast_NameActionUnit_No.MonthTermMonthlyFeesPreviousPrevious Row
2Jan-2016-JanSmithNew190211$ 184.49$ -  
3Feb-2017-FebJonesNew190211$ 184.49$ -Expire14
4Mar-2020-MarHuntExpire202611$ 184.49$ -  
5Apr-2021-AprJohnsonExpire202611$ 184.49$ -Expire4
6May-2023-MayMillsRenew202611$ 184.49$ -Expire5
7Jun-2024-JunDunnRenew202611$ 184.49$ -Renew6
8Jul-2026-JulWatsonRenew311811$ 184.49$ -  
9Aug-2027-AugJonesNew190211$ 184.49$ -New3
10Sep-2028-SepFeenNew202611$ 184.49$ -Renew7
11Oct-2030-OctLoorExpire202611$ 184.49$ -New10
12Nov-201-DecKlausNew202611$ 184.49$ -Expire11
13Dec-202-JanBrundonNew202611$ 184.49$ -New12
14Jan-203-FebSopeExpire190211$ 184.49$ -New2
15Feb-217-MarKeelExpire190211$ 184.49$ -New9
16Mar-218-AprNuneExpire190211$ 184.49$ -Expire15
17Apr-2110-MayDresterRenew311811$ 184.49$ -Renew8
18May-2111-JunOlantRenew190211$ 184.49$ -Expire16
Sheet1 (4)
Cell Formulas
RangeFormula
K2:K18K2=IFERROR(INDEX([Action],AGGREGATE(15,6,ROW([Action])-ROW(Leasing_Data[[#Headers],[Action]])/(([Unit_No.]=[@[Unit_No.]])*([Start_Date]=AGGREGATE(14,6,[Start_Date]/(([Start_Date]<[@[Start_Date]])*([Unit_No.]=[@[Unit_No.]])),1))),1)),"")
L2:L18L2=IFERROR(AGGREGATE(15,6,ROW([Action])-ROW(Leasing_Data[[#Headers],[Action]])/(([Unit_No.]=[@[Unit_No.]])*([Start_Date]=AGGREGATE(14,6,[Start_Date]/(([Start_Date]<[@[Start_Date]])*([Unit_No.]=[@[Unit_No.]])),1))),1)+ROW(Leasing_Data[[#Headers],[Previous Row]]),"")
Named Ranges
NameRefers ToCells
Action='Sheet1 (4)'!$E$2:$E$18K2:L18
Start_Date='Sheet1 (4)'!$B$2:$B$18K2:L18
Unit_No.='Sheet1 (4)'!$F$2:$F$18K2:L18
Cells with Conditional Formatting
CellConditionCell FormatStop If True
E2:E99Expression=K2&E2="RenewNew"textNO
E2:E99Expression=K2&E2="ExpireRenew"textNO
E2:E99Expression=K2&E2="ExpireExpire"textNO
E2:E99Expression=K2&E2="NewNew"textNO
 
Upvote 0

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hi Toadstool,

Sorry about the late response. I would like to share the spreadsheet with you as even this second "check" formula that you shared is not working correctly.

I do appreciate your patience in helping me with this. How would you like me to share the spreadsheet with you?

Thank you,

Rigel
 
Upvote 0
You can share on Google Drive or Dropbox but make sure you've anonymized the data.

P.S. If you look at my last example can you identify which rows are wrong?
 
Upvote 0
I have removed sensitive data to the best of my ability.

Your example is correct. The error only occurs when I transfer onto my spreadsheet.

What would be a good email to share the file with?
 
Upvote 0
I have removed sensitive data to the best of my ability.

Your example is correct. The error only occurs when I transfer onto my spreadsheet.

What would be a good email to share the file with?
OK, I've taken a look at the large dataset. After looking at the data, with several duplicate Start Dates for the Action of a Unit, I concluded there was no key field available to find the previous entry for a Unit. This left the only option of relying on its actual position in the dataset to decide which is the previous action.

I've made the changes to the cut-down sample and show the mini-sheet below.


rigeljr-Temporary-Data-V3.xlsx
BCEFGHKL
1Leasing Data
2Start DateRecorded DateActionUnit No.Months PaidTermPreviousCheck
3Jan-1711-JanNew103011  
4Jan-1713-JanNew103411  
5Jan-1713-JanNew10731212  
6Jan-1713-JanNew108111  
7Jan-1713-JanNew109311  
8Jan-1714-JanNew103511  
9Jan-1714-JanNew107711  
10Jan-1719-JanNew108311  
11Jan-1721-JanNew104611  
12Jan-1721-JanNew108411  
13Jan-1728-JanNew103311  
14Feb-173-FebNew108711  
15Feb-176-FebNew103211  
16Feb-178-FebNew103111  
17Feb-179-FebNew108511  
18Feb-1710-FebNew106711  
19Jan-1711-FebRenew103011 New 3
20Jan-1712-FebRenew103411 New 4
21Jan-1713-FebExpire107711 New 9
22Jan-1713-FebRenew108111 New 6
23Feb-1713-FebNew108911  
24Jan-1713-FebRenew109311 New 7
25Jan-1714-FebRenew103511 New 8
26Feb-1714-FebNew107711 New 21
Report Data
Cell Formulas
RangeFormula
K3:K26K3=IF([@Check]="","",INDEX([Action],[@Check]))
L3:L26L3=IFERROR(AGGREGATE(14,6,ROW([Action])-ROW(Leasing_Data[[#Headers],[Action]])/(([Unit No.]=[@[Unit No.]])*(ROW([Action])<ROW())),1)+ROW(Leasing_Data[[#Headers],[Check]]),"")
Cells with Conditional Formatting
CellConditionCell FormatStop If True
E3:E13810Expression=E3&K3="NewNew"textNO
E3:E13810Expression=E3&K3="ExpireExpire"textNO
E3:E13810Expression=E3&K3="ExpireRenew"textNO
E3:E13810Expression=E3&K3="RenewNew"textNO
B3:B13810Cell Value=0textNO
Cells with Data Validation
CellAllowCriteria
E3:E26List=INDIRECT("Actions[Leasing Actions]")
 
Upvote 0
Solution

Forum statistics

Threads
1,216,750
Messages
6,132,505
Members
449,730
Latest member
SeanHT

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