VBA to find values and reduce cell X by cell Y

MichaelRSnow

Active Member
Joined
Aug 3, 2010
Messages
409
Hi All

I'm sure there is a simple piece of VBA to do this but can't work out how.

For example, If column A has a list of letters, Column B a number, and C a greater number i.e.

Column A Column B Column C
A 2 10
B 4 8
C 6 14
D 8 20
E 10 18
A 1 19
B 3 7
C 5 11
D 7 13
E 9 9

Is it possible to locate the letter B, reduce the value in column C by the value in column B and then delete the value from column B. Actual data is 30 thousand rows long hence the need to automate it via VBA.
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Code:
Sub ReduceStock()

Dim rng as Range
Dim cel as Range

Set rng = Activesheet.Range("A1:A" & ActiveSheet.Range("A" & Activesheet.Rows.Count).End(xlUp).Row)

For each cel in rng

If trim(cel) = "B" then

cel.Offset(,2) = cel.offset(,2)-cel.offset(,1)
cel.offset(,1) = ""

end if

next cel

end sub
 
Upvote 0
Code:
Sub ReduceStock()

Dim rng as Range
Dim cel as Range

Set rng = Activesheet.Range("A1:A" & ActiveSheet.Range("A" & Activesheet.Rows.Count).End(xlUp).Row)

For each cel in rng

If trim(cel) = "B" then

cel.Offset(,2) = cel.offset(,2)-cel.offset(,1)
cel.offset(,1) = ""

end if

next cel

end sub

Perfect, thank you so much :biggrin:
 
Upvote 0

Forum statistics

Threads
1,214,551
Messages
6,120,156
Members
448,948
Latest member
spamiki

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