VBA to change Subtotal string in active worksheet (with sample)

MikeL

Active Member
Joined
Mar 17, 2002
Messages
492
Office Version
  1. 365
Platform
  1. Windows
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

replace subtotal string.xlsx
ABCDEFGHI
1BEFOREAFTER
2statecategoryitemamountstatecategoryitemamount
3ALASKAALASKA
4fruitfruit
5apple50apple50
6subtotal fruit50subtotal fruit50
7
8veggieveggie
9beans25beans25
10subtotal veggie25subtotal veggie25
11
12
13IDAHOIDAHO
14fruitfruit
15berries100berries100
16subtotal fruit100subtotal fruit100
17
18veggieveggie
19corn300corn300
20subtotal veggie300subtotal CORN300
21
22veggieveggie
23beans300beans300
24subtotal veggie300subtotal BEANS300
25IDAHO continuedIDAHO continued
26fruitfruit
27pears35pears35
28subtotal fruit35subtotal fruit35
29
30veggieveggie
31carrots45carrots45
32subtotal veggie45subtotal CARROTS45
UPDATE SUBTOTAL
Cell Formulas
RangeFormula
D6,I32,D32,I28,D28,I24,D24,I20,D20,I16,D16,I10,D10,I6D6=SUBTOTAL(9,D5)
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,223,909
Messages
6,175,312
Members
452,634
Latest member
cpostell

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