3 Case Scenario VBA Code

jalrs

Active Member
Joined
Apr 6, 2022
Messages
300
Office Version
  1. 365
Platform
  1. Windows
Hello guys,

I don't know how to approach this nor if it is the right request to make. I believe with the attached screenshots will make it easier to understand.
So what I would like to is:

1st : Check each material on column C
2nd: 1st case - If the sum of column M is equal to 0 for each material, then delete those lines (water on the example)
2nd case - If the sum of column M is # 0 for each material, then leave it like that (coke on the example)
3rd case - If the sum of column M is # 0 and column L is greater than 0, add a new line under the one where column L is greater than 0 where column K = K-L from previous row, colum L is now 0, and column M equals to column K value. Plus Column E new line is +1 regarding the previous line value. Rest of the values should be equal to the ones on the previous line, except for the date that should be left empty. (tea example. date not correct on the output.png sorry)

Hope this is possible and hope someone can help me.

Please look at the input vs output attachment.

Any help is greatly appreciated.

Thanks
 

Attachments

  • input.png
    input.png
    18.9 KB · Views: 21
  • output.png
    output.png
    21.9 KB · Views: 22
I am 2nd guessing what I gave you previously in terms of being able to not handle the length of the string.
Please add the 2nd line below, the first just being for context.

VBA Code:
                                        re = Replace(arr(k, 5), Val(arr(k, 5)), Val(arr(k, 5)) + 1)
                                        re = Right(re, Len(arr(k, 5)))
Hey Alex,

As promised, I tested and can confirm macro is still working accordingly.

Thank you for your help on this!
 
Upvote 0

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
No problem. What I had before would be 1 leading zero out when the line no increased from 9 to 10 and from 99 to 100 etc.
 
Upvote 0
No problem. What I had before would be 1 leading zero out when the line no increased from 9 to 10 and from 99 to 100 etc.
Thanks for explaining Alex.

I double checked and all leading zeroes are correct.

Thank you :)
 
Upvote 0

Forum statistics

Threads
1,214,654
Messages
6,120,758
Members
448,991
Latest member
Hanakoro

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