Automatically insert the row by finding the particular cell value

mayaa_mmm

Board Regular
Joined
Jul 30, 2014
Messages
54
Office Version
  1. 2010
Platform
  1. Windows
[TABLE="width: 308"]
<colgroup><col><col><col></colgroup><tbody>[TR]
[TD]A column[/TD]
[TD]B column[/TD]
[TD]C Column[/TD]
[/TR]
[TR]
[TD]Name[/TD]
[TD]orders[/TD]
[TD]Quantity[/TD]
[/TR]
[TR]
[TD]David[/TD]
[TD]Food order[/TD]
[TD="align: right"]100[/TD]
[/TR]
[TR]
[TD]David[/TD]
[TD]Friuts order[/TD]
[TD="align: right"]50[/TD]
[/TR]
[TR]
[TD]William[/TD]
[TD]Food order[/TD]
[TD="align: right"]10[/TD]
[/TR]
[TR]
[TD]William[/TD]
[TD]Friuts order[/TD]
[TD="align: right"]5[/TD]
[/TR]
[TR]
[TD]William[/TD]
[TD]material order[/TD]
[TD="align: right"]100[/TD]
[/TR]
[TR]
[TD]Rita[/TD]
[TD]Food order[/TD]
[TD="align: right"]30[/TD]
[/TR]
[TR]
[TD]Rita[/TD]
[TD]stock order[/TD]
[TD="align: right"]40[/TD]
[/TR]
[TR]
[TD]Rita[/TD]
[TD]material order[/TD]
[TD="align: right"]50[/TD]
[/TR]
[TR]
[TD]Rita[/TD]
[TD]Friuts order[/TD]
[TD="align: right"]20[/TD]
[/TR]
[TR]
[TD]Rita[/TD]
[TD]thread order[/TD]
[TD="align: right"]60[/TD]
[/TR]
</tbody>[/TABLE]


I want to the insert the row below the fruits order cell value.
My output should be like

[TABLE="width: 323"]
<colgroup><col><col><col></colgroup><tbody>[TR]
[TD]A Column[/TD]
[TD]B Column[/TD]
[TD]C Column[/TD]
[/TR]
[TR]
[TD]Name[/TD]
[TD]orders[/TD]
[TD]Quantity[/TD]
[/TR]
[TR]
[TD]David[/TD]
[TD]Food order[/TD]
[TD="align: right"]100[/TD]
[/TR]
[TR]
[TD]David[/TD]
[TD]Friuts order[/TD]
[TD="align: right"]50[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]William[/TD]
[TD]Food order[/TD]
[TD="align: right"]10[/TD]
[/TR]
[TR]
[TD]William[/TD]
[TD]Friuts order[/TD]
[TD="align: right"]5[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]William[/TD]
[TD]material order[/TD]
[TD="align: right"]100[/TD]
[/TR]
[TR]
[TD]Rita[/TD]
[TD]Food order[/TD]
[TD="align: right"]30[/TD]
[/TR]
[TR]
[TD]Rita[/TD]
[TD]stock order[/TD]
[TD="align: right"]40[/TD]
[/TR]
[TR]
[TD]Rita[/TD]
[TD]material order[/TD]
[TD="align: right"]50[/TD]
[/TR]
[TR]
[TD]Rita[/TD]
[TD]Friuts order[/TD]
[TD="align: right"]20[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Rita[/TD]
[TD]thread order[/TD]
[TD="align: right"]60[/TD]
[/TR]
</tbody>[/TABLE]
 
Hi Mayaa,

you may use below code for this....

Code:
Sub InsertRow()
Dim c As Long
c = 2
With ActiveSheet
While (.Cells(c, 2).Value <> "")
    If Trim(UCase(.Cells(c, 2).Value)) = UCase("Friuts order") Then
        .Cells(c, 2).Offset(1, 0).EntireRow.Insert
        c = c + 1
    End If
    c = c + 1
Wend
End With
End Sub
 
Upvote 0
Excellent macro. It is working fine for me.

Is it possible by finding the "fruit order" cell and fill down values in the new row with values in the fruit order and replace the "fruit order" cell as an " fruit order done" cell alone.

it reduce my two step of work
 
Upvote 0
Here you go .... Cheers
Code:
Sub InsertRow()
Dim c As Long
c = 2
With ActiveSheet
While (.Cells(c, 2).Value <> "")
    If Trim(UCase(.Cells(c, 2).Value)) = UCase("Friuts order") Then
        .Cells(c, 2).Offset(1, 0).EntireRow.Insert
        .Cells(c, 2).Offset(0, -1).Resize(2, 3).FillDown
        .Cells(c, 2).Offset(1, 0).Value = "Fruit Order Done"
        .Cells(c, 2).Offset(1, -1).Resize(1, 3).Font.Bold = True
        c = c + 1
    End If
    c = c + 1
Wend
End With
End Sub


Just correct spelling of Fruit whatever it should in Macro as well well in excel file... :stickouttounge:
 
Upvote 0

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