Inserting/reserving row when condition is met using vba code

simke

New Member
Joined
Sep 19, 2022
Messages
5
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Dear all,

I am working on a project that I need to reserve part of the table if some conditions are met. For example I have a table and when I select two conditions with drop down list(type and profile: green color). Cyl name(CL125) and quantity 10, this two are filled manualy. Now I want that with vba excel should filter with first two criteria(type(column B and profile(column C) and insert for each not already reserved cell(column G), fill cell on column "G", ten new cyl name(in this example CL125). Below in the table is filled with blue. Once this new data are inserted it will also automaticaly insert column H(date) and column I(time). Below is a test example because I am testing/figure it out how to make this automation with vba and I didn't find any solution. Could you please help me with this issue. Thank you very much

TEST_02.jpg
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Maybe this UNTESTED as I won't type all your data in to test it !!
VBA Code:
Sub MM1()
Dim lr As Long, r As Long
lr = Cells(Rows.Count, "A").End(xlUp).Row
For r = 7 To lr
    If Cells(r, 2) = Cells(1, 12) And Cells(r, 3) = Cells(2, 12) And Cells(r, 7) = "" Then
    Cells(r, 7) = Cells(3, 12)
    Cells(r, 8) = Date
    With Cells(r, 9)
    .Value = Time
    .NumberFormat = "hh:mm:ss"
    End With
Next r
End Sub
 
Upvote 0
Hi Michael,

Thank you for the code. Your code is excellent. I put only end if at the end and is working almost as I wanted. I need only to put for example if there is quantity 2, that will reserve only 2 rows for the mentioned criteria. Now is inserting me in all rows where criteria is met. In below table is highlighted in yellow row 4 and in the table also two rows are highlighted in yellow.

Could you please help me to modifie the code so that will take also qty into consideretion. Thank you

TEST_03.jpg
 
Upvote 0

Forum statistics

Threads
1,223,958
Messages
6,175,629
Members
452,661
Latest member
Nonhle

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