Need to add rows based on previous column values

csimpson24

New Member
Joined
Feb 22, 2018
Messages
22
Hello all,

Ripping my hair out over this one and cannot find an answer anywhere. Here is an example of my data. I want to automatically add a new row after the last job entry. So in the example below, I would add a new row for job 106144 with Opr 60, a new row for job 108422 with Opr 30, a new row for Job 108466 with Opr 20, and so on. Any help would be GREATLY appreciated. It's been years since I've written in VBA by the way.

JobNumCompanyPlantAsmOprOperation

<tbody>
</tbody>
106144GCBGCB010MECHENG
106144GCBGCB020MACH
106144GCBGCB030FAB
106144GCBGCB040ASSEM
106144GCBGCB050TEST

<colgroup><col><col span="2"><col span="2"><col></colgroup><tbody>
</tbody>

<tbody>
</tbody>

108422GCBGCB010FAB
108422GCBGCB020MACH

<colgroup><col><col span="2"><col span="2"><col></colgroup><tbody>
</tbody>
108446GCBGCB010MACH
108449GCBGCB010FAB
108449GCBGCB020MACH

<colgroup><col><col span="2"><col span="2"><col></colgroup><tbody>
</tbody>
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Hi & welcome to the board.

You haven't give us much to go on, but try this
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

   If Target.CountLarge > 1 Then Exit Sub
   If Target.Column <> 6 Then Exit Sub
Application.EnableEvents = False
   With Target
      .Offset(1).EntireRow.Insert
      .Offset(, -5).Resize(2, 5).FillDown
      .Offset(1, -1).Value = .Offset(, -1).Value + 10
   End With
Application.EnableEvents = True
End Sub
It needs to go in the sheet module.
 
Upvote 0
Thank you! I can provide more information. What do you need? Here's a portion of my spreadsheet. The red is an example of what I would like to have inserted automatically.
Once I place your code into sheet view, how does it run?

ABCDEF
JobNumCompanyPlantAsmOprOperation
106144GCBGCB010MECHENG
106144GCBGCB020MACH
106144GCBGCB030FAB
106144GCBGCB040ASSEM
106144GCBGCB050TEST
106144GCBGCB060PAINT-PC
108037GCBGCB010MACH
108358GCBGCB010MACH
108396GCBGCB010MACH
108422GCBGCB010FAB
108422GCBGCB020MACH
108423GCBGCB010FAB
108423GCBGCB020MACH
108426GCBGCB010MACH
108426GCBGCB020REWORK
108427GCBGCB010FAB
108427GCBGCB020MACH
108431GCBGCB010MACH
108432GCBGCB010FAB
108432GCBGCB020MACH
108436GCBGCB010FAB
108437GCBGCB010FAB
108438GCBGCB010FAB
108439GCBGCB010FAB
108440GCBGCB010FAB
108446GCBGCB010MACH
108449GCBGCB010FAB
108449GCBGCB020MACH
108480GCBGCB010ASSEM
108480GCBGCB020FAB
108480GCBGCB030MACH
108485GCBGCB010MACH

<colgroup><col><col span="2"><col span="2"><col></colgroup><tbody>
</tbody>
 
Upvote 0
When do you want this to run?
When you enter data in a particular column, or whenever you feel like it?
How will the macro know what value to put in col F?
 
Upvote 0
When do you want this to run?
When you enter data in a particular column, or whenever you feel like it?
How will the macro know what value to put in col F?

I would like to be able to run it when I need to run it. Column F would always be PAINT-PC.
 
Upvote 0
Ok, try
Code:
Sub AddRow()

   Dim Rw As Long
   
   For Rw = Range("A" & Rows.Count).End(xlUp).Row To 2 Step -1
      If Range("A" & Rw) <> Range("A" & Rw + 1).Value Then
         Rows(Rw + 1).Insert
         Range("A" & Rw).Resize(2, 3).FillDown
         Range("E" & Rw + 1).Value = Range("E" & Rw).Value + 10
         Range("F" & Rw + 1).Value = "Paint-PC"
      End If
   Next Rw
         
End Sub
 
Upvote 0
Works amazingly well! One small request. Column D is blank in the new row. Where do I add that in your code? I am blown away with how much I've lost since doing VBA 10 years ago... lol
 
Upvote 0
I can't count!!
it should be
Code:
Range("A" & Rw).Resize(2, [COLOR=#ff0000]4[/COLOR]).FillDown
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,387
Members
448,957
Latest member
Hat4Life

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