Hi,
I would like to use VBA to replace string in a Subtotal cell if two conditions are met.
1) If Column A contains 'Idaho' offset DOWN and RIGHT and look at Column B
2) If the offset finds 'Veggie' in Column B, replace the string 'veggie' in 'Subtotal Veggie' with string under Item in Col C by offset 1 cell down and to right. ie Offset(1, 1)
Sample Before and After (blue conditions, red before and after results)
Thanks in advance
I would like to use VBA to replace string in a Subtotal cell if two conditions are met.
1) If Column A contains 'Idaho' offset DOWN and RIGHT and look at Column B
2) If the offset finds 'Veggie' in Column B, replace the string 'veggie' in 'Subtotal Veggie' with string under Item in Col C by offset 1 cell down and to right. ie Offset(1, 1)
Sample Before and After (blue conditions, red before and after results)
Thanks in advance
replace subtotal string.xlsx | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | |||
1 | BEFORE | AFTER | |||||||||
2 | state | category | item | amount | state | category | item | amount | |||
3 | ALASKA | ALASKA | |||||||||
4 | fruit | fruit | |||||||||
5 | apple | 50 | apple | 50 | |||||||
6 | subtotal fruit | 50 | subtotal fruit | 50 | |||||||
7 | |||||||||||
8 | veggie | veggie | |||||||||
9 | beans | 25 | beans | 25 | |||||||
10 | subtotal veggie | 25 | subtotal veggie | 25 | |||||||
11 | |||||||||||
12 | |||||||||||
13 | IDAHO | IDAHO | |||||||||
14 | fruit | fruit | |||||||||
15 | berries | 100 | berries | 100 | |||||||
16 | subtotal fruit | 100 | subtotal fruit | 100 | |||||||
17 | |||||||||||
18 | veggie | veggie | |||||||||
19 | corn | 300 | corn | 300 | |||||||
20 | subtotal veggie | 300 | subtotal CORN | 300 | |||||||
21 | |||||||||||
22 | veggie | veggie | |||||||||
23 | beans | 300 | beans | 300 | |||||||
24 | subtotal veggie | 300 | subtotal BEANS | 300 | |||||||
25 | IDAHO continued | IDAHO continued | |||||||||
26 | fruit | fruit | |||||||||
27 | pears | 35 | pears | 35 | |||||||
28 | subtotal fruit | 35 | subtotal fruit | 35 | |||||||
29 | |||||||||||
30 | veggie | veggie | |||||||||
31 | carrots | 45 | carrots | 45 | |||||||
32 | subtotal veggie | 45 | subtotal CARROTS | 45 | |||||||
UPDATE SUBTOTAL |
Cell Formulas | ||
---|---|---|
Range | Formula | |
D6,I32,D32,I28,D28,I24,D24,I20,D20,I16,D16,I10,D10,I6 | D6 | =SUBTOTAL(9,D5) |