finding a value >1 in a column, and insert row above or below and copy content and change the value to 1

sekar_r24

New Member
Joined
Apr 18, 2020
Messages
26
Office Version
  1. 2013
Platform
  1. Windows
Hi.,

01. I am having range of data, would like to find the value greater than in the column P (say 3) of the particular cell, and insert the row above or below (number (say 3) times - 1) (=3-1), and copy & paste the entire row, in the inserted rows and the change the value of the P column for the pasted values as 1. Also change the value of three into one.

02. Also the values in the column Q has to be separated, with the delimiter comma (, ) and the same has to be pasted in the Q column of the inserted rows, with each unique value.

Attached here with the sample data and expected output.

Could anyone help in this regard.

sample01.xlsx
ABCDEFGHIJKLMNOPQ
4LEFT_SIDE600 mm295 mm18 mm14142- Auburn Kaos OakWhite laminate448P414P414P414P650 mm345 mmSGHGMINIFIX SET1LEFT SIDE_WCD2D_800.0
5LEFT_SIDE600 mm295 mm18 mmWhite laminateWhite laminate448 P414P414P414P650 mm345 mmSGHG01LEFT SIDE_WCD2D_800.0
6LEFT_SIDE605 mm550 mm18 mmWhite laminateWhite laminate448P414P414P414P655 mm600 mmSGHG03LEFT SIDE PANEL_BC1D_200.0, LEFT SIDE_BC3DRW_600.0, LEFT SIDE_BCSCLH_960
7LEFT_SIDE605 mm600 mm18 mmWhite laminateWhite laminate448P414P414P414P655 mm650 mmSGHG01LEFT_SIDE_BC2DS_700.0
8LEFT_SIDE705 mm570 mm18 mmWhite laminateWhite laminate448P414P414P414P755 mm620 mmSGHG01LEFT SIDE_BC1DCY_600.0
9Ledge_01200 mm1072 mm18 mm14142- Auburn Kaos Oak14142- Auburn Kaos Oak448P448P448P448P250 mm1122 mmSG1LEDGE
10Ledge_02200 mm1072 mm18 mm14142- Auburn Kaos Oak14142- Auburn Kaos Oak448P448P448P448P250 mm1122 mmSG1LEDGE
11Ledge_03300 mm640 mm25 mm14142- Auburn Kaos Oak14142- Auburn Kaos Oak448P448P448P448P350 mm690 mmSG1Exposed
12Ledge_04300 mm640 mm25 mm14142- Auburn Kaos Oak14142- Auburn Kaos Oak448P448P448P448P350 mm690 mmSG1Exposed
13Ledge_05300 mm640 mm25 mm14142- Auburn Kaos Oak14142- Auburn Kaos Oak448P448P448P448P350 mm690 mmSG1Exposed
14Ledge_06300 mm640 mm25 mm14142- Auburn Kaos Oak14142- Auburn Kaos Oak448P448P448P448P350 mm690 mmSG1Exposed
15Ledge_07300 mm640 mm25 mm14142- Auburn Kaos Oak14142- Auburn Kaos Oak448P448P448P448P350 mm690 mmSG1Exposed
16RAIL_A564 mm100 mm18 mmWhite laminateWhite laminate448P414P414P414P614 mm150 mmSG02FRONT RAIL_BC3DRW_600.0, RAIL FRONT_BC1DCY_600.0
17RAIL_A664 mm100 mm18 mmWhite laminateWhite laminate448P414P414P414P714 mm150 mmSG01RAIL FRONT_BC2DS_700.0
18RAIL_A924 mm100 mm18 mmWhite laminateWhite laminate448P414P414P414P974 mm150 mmSG01RAIL A_BCSCLH_960
19RAIL_B164 mm550 mm18 mmWhite laminateWhite laminate448P414P414P414P214 mm600 mmSGHG01TOP PANEL_BC1D_200.0
20RAIL_B564 mm100 mm18 mmWhite laminateWhite laminate448P414P414P414P614 mm150 mmSGHG01TOP PANEL_BC1DCY_600.0
21RAIL_B564 mm550 mm18 mmWhite laminateWhite laminate448P414P414P414P614 mm600 mmSGHG01TOP PANEL_BC3DRW_600.0
22RAIL_B664 mm100 mm18 mmWhite laminateWhite laminate448P414P414P414P714 mm150 mmSGHG01TOP PANEL_BC2DS_700.0
23RAIL_B764 mm295 mm18 mmWhite laminateWhite laminate448 P414P414P414P814 mm345 mmSGHGMINIFIX SET1TOP PANEL_WCD2D_800.0
24RAIL_B764 mm295 mm18 mmWhite laminateWhite laminate448P414P414P414P814 mm345 mmSGHGMINIFIX SET1TOP PANEL_WCD2D_800.0
25RAIL_B924 mm100 mm18 mmWhite laminateWhite laminate448P414P414P414P974 mm150 mmSGHG01RAIL B_BCSCLH_960
26RIGHT_SIDE600 mm295 mm18 mm14142- Auburn Kaos OakWhite laminate448 P414P414P414P650 mm345 mmSGHGMINIFIX SET1RIGHT SIDE_WCD2D_800.0
27RIGHT_SIDE600 mm295 mm18 mm14142- Auburn Kaos OakWhite laminate448P414P414P414P650 mm345 mmSGHGMINIFIX SET1RIGHT SIDE_WCD2D_800.0
28RIGHT_SIDE605 mm550 mm18 mmWhite laminateWhite laminate448P414P414P414P655 mm600 mmSGHG03RIGHT SIDE_BC1D_200.0, RIGHT SIDE_BC3DRW_600.0, RIGHT SIDE_BCSCLH_960
29RIGHT_SIDE605 mm600 mm18 mmWhite laminateWhite laminate448P414P414P414P655 mm650 mmSGHG01RIGHT_SIDE_BC2DS_700.0
30RIGHT_SIDE705 mm570 mm18 mmWhite laminateWhite laminate448P414P414P414P755 mm620 mmSGHG01RIGHT SIDE_BC1DCY_600.0
Sheet1




sample01.xlsx
ABCDEFGHIJKLMNOPQ
38LEFT_SIDE600 mm295 mm18 mm14142- Auburn Kaos OakWhite laminate448P414P414P414P650 mm345 mmSGHGMINIFIX SET1LEFT SIDE_WCD2D_800.0
39LEFT_SIDE600 mm295 mm18 mmWhite laminateWhite laminate448 P414P414P414P650 mm345 mmSGHG01LEFT SIDE_WCD2D_800.0
40LEFT_SIDE605 mm550 mm18 mmWhite laminateWhite laminate448P414P414P414P655 mm600 mmSGHG01LEFT SIDE PANEL_BC1D_200.0
41LEFT_SIDE605 mm550 mm18 mmWhite laminateWhite laminate448P414P414P414P655 mm600 mmSGHG01 LEFT SIDE_BC3DRW_600.0
42LEFT_SIDE605 mm550 mm18 mmWhite laminateWhite laminate448P414P414P414P655 mm600 mmSGHG01 LEFT SIDE_BCSCLH_960
43LEFT_SIDE605 mm600 mm18 mmWhite laminateWhite laminate448P414P414P414P655 mm650 mmSGHG01LEFT_SIDE_BC2DS_700.0
44LEFT_SIDE705 mm570 mm18 mmWhite laminateWhite laminate448P414P414P414P755 mm620 mmSGHG01LEFT SIDE_BC1DCY_600.0
45Ledge_01200 mm1072 mm18 mm14142- Auburn Kaos Oak14142- Auburn Kaos Oak448P448P448P448P250 mm1122 mmSG1LEDGE
46Ledge_02200 mm1072 mm18 mm14142- Auburn Kaos Oak14142- Auburn Kaos Oak448P448P448P448P250 mm1122 mmSG1LEDGE
47Ledge_03300 mm640 mm25 mm14142- Auburn Kaos Oak14142- Auburn Kaos Oak448P448P448P448P350 mm690 mmSG1Exposed
48Ledge_04300 mm640 mm25 mm14142- Auburn Kaos Oak14142- Auburn Kaos Oak448P448P448P448P350 mm690 mmSG1Exposed
49Ledge_05300 mm640 mm25 mm14142- Auburn Kaos Oak14142- Auburn Kaos Oak448P448P448P448P350 mm690 mmSG1Exposed
50Ledge_06300 mm640 mm25 mm14142- Auburn Kaos Oak14142- Auburn Kaos Oak448P448P448P448P350 mm690 mmSG1Exposed
51Ledge_07300 mm640 mm25 mm14142- Auburn Kaos Oak14142- Auburn Kaos Oak448P448P448P448P350 mm690 mmSG1Exposed
52RAIL_A564 mm100 mm18 mmWhite laminateWhite laminate448P414P414P414P614 mm150 mmSG01FRONT RAIL_BC3DRW_600.0
53RAIL_A564 mm100 mm18 mmWhite laminateWhite laminate448P414P414P414P614 mm150 mmSG01 RAIL FRONT_BC1DCY_600.0
54RAIL_A664 mm100 mm18 mmWhite laminateWhite laminate448P414P414P414P714 mm150 mmSG01RAIL FRONT_BC2DS_700.0
55RAIL_A924 mm100 mm18 mmWhite laminateWhite laminate448P414P414P414P974 mm150 mmSG01RAIL A_BCSCLH_960
56RAIL_B164 mm550 mm18 mmWhite laminateWhite laminate448P414P414P414P214 mm600 mmSGHG01TOP PANEL_BC1D_200.0
57RAIL_B564 mm100 mm18 mmWhite laminateWhite laminate448P414P414P414P614 mm150 mmSGHG01TOP PANEL_BC1DCY_600.0
58RAIL_B564 mm550 mm18 mmWhite laminateWhite laminate448P414P414P414P614 mm600 mmSGHG01TOP PANEL_BC3DRW_600.0
59RAIL_B664 mm100 mm18 mmWhite laminateWhite laminate448P414P414P414P714 mm150 mmSGHG01TOP PANEL_BC2DS_700.0
60RAIL_B764 mm295 mm18 mmWhite laminateWhite laminate448 P414P414P414P814 mm345 mmSGHGMINIFIX SET1TOP PANEL_WCD2D_800.0
61RAIL_B764 mm295 mm18 mmWhite laminateWhite laminate448P414P414P414P814 mm345 mmSGHGMINIFIX SET1TOP PANEL_WCD2D_800.0
62RAIL_B924 mm100 mm18 mmWhite laminateWhite laminate448P414P414P414P974 mm150 mmSGHG01RAIL B_BCSCLH_960
63RIGHT_SIDE600 mm295 mm18 mm14142- Auburn Kaos OakWhite laminate448 P414P414P414P650 mm345 mmSGHGMINIFIX SET1RIGHT SIDE_WCD2D_800.0
64RIGHT_SIDE600 mm295 mm18 mm14142- Auburn Kaos OakWhite laminate448P414P414P414P650 mm345 mmSGHGMINIFIX SET1RIGHT SIDE_WCD2D_800.0
65RIGHT_SIDE605 mm550 mm18 mmWhite laminateWhite laminate448P414P414P414P655 mm600 mmSGHG01RIGHT SIDE_BC1D_200.0
66RIGHT_SIDE605 mm550 mm18 mmWhite laminateWhite laminate448P414P414P414P655 mm600 mmSGHG01RIGHT SIDE_BC3DRW_600.0
67RIGHT_SIDE605 mm550 mm18 mmWhite laminateWhite laminate448P414P414P414P655 mm600 mmSGHG01RIGHT SIDE_BCSCLH_960
68RIGHT_SIDE605 mm600 mm18 mmWhite laminateWhite laminate448P414P414P414P655 mm650 mmSGHG01RIGHT_SIDE_BC2DS_700.0
69RIGHT_SIDE705 mm570 mm18 mmWhite laminateWhite laminate448P414P414P414P755 mm620 mmSGHG01RIGHT SIDE_BC1DCY_600.0
Sheet1
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Give this a try with a copy of your data.

VBA Code:
Sub Split_Rows()
  Dim r As Long, num As Long
  
  Application.ScreenUpdating = False
  For r = Range("P" & Rows.Count).End(xlUp).Row To 4 Step -1
    num = Range("P" & r).Value
    If num > 1 Then
      Rows(r).Copy
      Rows(r + 1).Resize(num - 1).Insert
      Range("P" & r).Resize(num).Value = 1
      Range("Q" & r).Resize(num).Value = Application.Transpose(Split(Replace(Range("Q" & r).Value, ", ", ","), ","))
    End If
  Next r
  Application.CutCopyMode = False
  Application.ScreenUpdating = True
End Sub
 
Upvote 0
Cross posted Finding a value greater than one in particular column, insert row, paste and change the value - OzGrid Free Excel/VBA Help Forum

While we do allow Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules). This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0
Hi.,
Regret for the inconvenience. Defintely will do henceforth.

Cross posted Finding a value greater than one in particular column, insert row, paste and change the value - OzGrid Free Excel/VBA Help Forum

While we do allow Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules). This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0
Sub Split_Rows() Dim r As Long, num As Long Application.ScreenUpdating = False For r = Range("P" & Rows.Count).End(xlUp).Row To 4 Step -1 num = Range("P" & r).Value If num > 1 Then Rows(r).Copy Rows(r + 1).Resize(num - 1).Insert Range("P" & r).Resize(num).Value = 1 Range("Q" & r).Resize(num).Value = Application.Transpose(Split(Replace(Range("Q" & r).Value, ", ", ","), ",")) End If Next r Application.CutCopyMode = False Application.ScreenUpdating = True End Sub

Hi.,

Thanks for your support. Works good. Great!

Could you explain why the for loop is upto 4 ?
Rich (BB code):
For r = Range("P" & Rows.Count).End(xlUp).Row To 4 Step -1
 
Last edited:
Upvote 0
Hi.,

Thanks for your support. Works good. Great!

Could you explain why the for loop is upto 4 ?
Rich (BB code):
For r = Range("P" & Rows.Count).End(xlUp).Row To 4 Step -1

Got it. it is for the no of rows left empty on the top of the data!
 
Upvote 0
You're welcome. Glad to help. :)

Just to clarify, the 4 should be the top row that needs to be checked. I used 4 because that was the top row as far as knew from your XL2BB sheet in post 1.
 
Upvote 0

Forum statistics

Threads
1,214,920
Messages
6,122,279
Members
449,075
Latest member
staticfluids

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