Color range on some condition with VBA

kashif.special2005

Active Member
Joined
Oct 26, 2009
Messages
443
Hi,

I have data, and I want to color cell on the column B ("Deposit") and column C ("Withdrawal"), on some condition.

Condition:-

Rule 1 :- Deposit & withdrawal entry for same date and same amount - color code "green"
Rule 2 :- Deposit & withdrawal entry for different dates with same amount - color code "yellow"
Rule 3 :- One Deposit but 2 withdrawals of same amount on same date then color code as "red"
Rule 4 :- Same date with different amounts of deposit and withdrawal then color code "red"
Rule 5 :- Only one entry either depoist or withdrawal then - color code "no color"

Data Heading:-

A1=Date
B1=Deposit
C1=Withdrawal

Data:-

A2_____02/07/2018___B2_____8605.59___C2_IS BLANK
A3_____02/07/2018___B3_IS BLANK___C3_____8606
A4_____02/08/2018___B4_IS BLANK___C4_____5086
A5_____02/08/2018___B5_____82320___C5_IS BLANK
A6_____02/08/2018___B6_IS BLANK___C6_____93534
A7_____02/08/2018___B7_____11214___C7_IS BLANK
A8_____02/14/2018___B8_IS BLANK___C8_____99.93
A9_____02/15/2018___B9_IS BLANK___C9_____29096
A10_____02/15/2018___B10_____29096___C10_IS BLANK
A11_____02/16/2018___B11_____1000000___C11_IS BLANK
A12_____02/16/2018___B12_IS BLANK___C12_____1000000
A13_____02/20/2018___B13_IS BLANK___C13_____1000000
A14_____02/20/2018___B14_IS BLANK___C14_____750
A15_____02/20/2018___B15_____1000000___C15_IS BLANK
A16_____02/20/2018___B16_____750___C16_IS BLANK
A17_____02/21/2018___B17_IS BLANK___C17_____68720
A18_____02/21/2018___B18_____75000___C18_IS BLANK
A19_____02/21/2018___B19_IS BLANK___C19_____6280
A20_____02/22/2018___B20_____200000___C20_IS BLANK
A21_____02/22/2018___B21_IS BLANK___C21_____200000
A22_____02/26/2018___B22_____1428193.84___C22_IS BLANK
A23_____02/26/2018___B23_IS BLANK___C23_____1428193.84
A24_____02/27/2018___B24_____1500000___C24_IS BLANK
A25_____02/27/2018___B25_IS BLANK___C25_____1500000
A26_____02/28/2018___B26_IS BLANK___C26_____4809.77
A27_____02/28/2018___B27_____500000___C27_IS BLANK
A28_____02/28/2018___B28_____3265431.51___C28_IS BLANK
A29_____02/28/2018___B29_IS BLANK___C29_____1500000
A30_____02/28/2018___B30_____700000___C30_IS BLANK
A31_____02/28/2018___B31_IS BLANK___C31_____700000
A32_____02/28/2018___B32_IS BLANK___C32_____500000
A33_____02/28/2018___B33_____1500000___C33_IS BLANK
A34_____02/28/2018___B34_IS BLANK___C34_____3265431.51

Here I showed some sample data, but reality the data is huge.

Please help me to achieve this task.

I am very new in VBA, and I don't know how to do this, please help me.

Thanks
Kashif
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
In your example you only have one column of dates so your rules don't make sense.
 
Upvote 0
Hi Trevor,

Thanks for reply, let me exaplain.

Rule 1 is saying that "
Deposit & withdrawal entry for same date and same amount - color code "green".

that means let say the date "
02/07/2018" has two entries and 1 for deposit and 2 is for withdrawal and if both the amount deposit and withdrawal are the same then this will meet "Rule 1" condition because the both the amount are same and the date is also the same, therefore both the cells background color will be green.

I hope, I am able clear your doubt.

Thanks
Kashif
 
Last edited:
Upvote 0
Hi,

Kindly request to all of great guys of excel community, please help me on this.

Thanks
Kashif

Can you post some data sample in a table?
You can post your excel table using some tools. Check here:
https://www.mrexcel.com/forum/about-board/508133-attachments.html

Or if you don't want to use some tool you can copy a simple table from worksheet.

To copy a simple table from worksheet:
1. In your worksheet select the table/range
2. In the menu, select border icon > select All Borders > then copy.
3. Back to the thread > in the reply box paste the table


A simple table would look like this:

NAMEID
MaysonA01
AmayaA03
CaydenA04

<tbody>
</tbody>
 
Upvote 0
Conditional formatting would work. Highlight the cells B2 + C2 and cells below, Under Home tab, Conditional formatting and New Rule and Formula rule add the following: =$B2=$C2 then colour Green
 
Upvote 0
Hi Trevor/Akuini,

Thanks for reply.

Trevor:- I can not apply conditional formatting because when we copy the conditional formatting cells to another cells conditional formatting not works.

Akuini:-

DateDepositWithdraw
2/7/20188605.59
2/7/2018 8606
2/8/2018 5086
2/8/201882320
2/8/2018 93534
2/8/201811214
2/14/2018 99.93
2/15/2018 29096
2/15/201829096
2/16/20181000000
2/16/2018 1000000
2/20/2018 1000000
2/20/2018 750
2/20/20181000000
2/20/2018750
2/21/2018 68720
2/21/201875000
2/21/2018 6280
2/22/2018200000
2/22/2018 200000
2/26/20181428193.84
2/26/2018 1428193.84
2/27/20181500000
2/27/2018 1500000
2/28/2018 4809.77
2/28/2018500000
2/28/20183265431.51
2/28/2018 1500000
2/28/2018700000
2/28/2018 700000
2/28/2018 500000
2/28/20181500000
2/28/2018 3265431.51

<colgroup><col><col span="2"></colgroup><tbody>
</tbody>

<colgroup><col><col span="2"></colgroup><tbody>
</tbody>
 
Upvote 0
Are these the expected results (color = red)?

A
B
C
1
Date​
Deposit​
Withdrawal​
2
07/02/2018​
8605,59​
3
07/02/2018​
8606,00​
4
08/02/2018​
5086,00​
5
08/02/2018​
82320,00​
6
08/02/2018​
93534,00​
7
08/02/2018​
11214,00​
8
14/02/2018​
99,93​
9
15/02/2018​
29096,00​
10
15/02/2018​
29096,00​
11
16/02/2018​
1000000,00​
12
16/02/2018​
1000000,00​
13
20/02/2018​
1000000,00​
14
20/02/2018​
750,00​
15
20/02/2018​
1000000,00​
16
20/02/2018​
750,00​
17
21/02/2018​
68720,00​
18
21/02/2018​
75000,00​
19
21/02/2018​
6280,00​
20
22/02/2018​
200000,00​
21
22/02/2018​
200000,00​
22
26/02/2018​
1428193,84​
23
26/02/2018​
1428193,84​
24
27/02/2018​
1500000,00​
25
27/02/2018​
1500000,00​
26
28/02/2018​
4809,77​
27
28/02/2018​
500000,00​
28
28/02/2018​
3265431,51​
29
28/02/2018​
1500000,00​
30
28/02/2018​
700000,00​
31
28/02/2018​
700000,00​
32
28/02/2018​
500000,00​
33
28/02/2018​
1500000,00​
34
28/02/2018​
3265431,51​

<tbody>
</tbody>


M.
 
Upvote 0
Hi Marcelo,

Thanks for reply.

However row number 9 and 10 should be green, because this lies in Rule 1, deposit and withdrawal date are same and amount also the same so the color should be green, and row 11 and 12 also will be green because this is also lies in Rule 1.

Thanks
Kashif
 
Upvote 0
Hi Marcelo,

Thanks for reply.

However row number 9 and 10 should be green, because this lies in Rule 1, deposit and withdrawal date are same and amount also the same so the color should be green, and row 11 and 12 also will be green because this is also lies in Rule 1.

Thanks
Kashif

What about rows 20-21, 22-23, 24-25, 30-31? Green?

M.
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,545
Members
449,089
Latest member
davidcom

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