Automatically insert new line

Gibbo_Steph

New Member
Joined
Oct 2, 2024
Messages
3
Office Version
  1. Prefer Not To Say
Platform
  1. Windows
Hi!

I have a sheet where I am recording attendance - lets say it looks something like this


PlaceDayName
NYCMonday
MiamiTuesday


(however I have more columns between day and name)

Name is a drop down with a defined set of names. I want to be able to select a name and then it automatically inserts a new line that replicates the cells of the line above it with the exception of the drop down cell. for example something like :



PlaceDayName
NYCMondayCathy
NYCMonday
MiamiTuesdayBob
MiamiTuesday


Essentially multiple people might be in NYC on Monday, and multiple people might be in Miami on Tuesday. Because multiple people will be updating this sheet I am trying to have it so that all they have to do is select a name under the right event, then itll be ready for more entries without anyone else adding lines or generally touching anything haha

I am assuming this will be a macro but I am not familiar enough with coding within Excel to do it

TIA
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
Welcome to the Board!

How many columns are in your list exactly (what are the first and last)?
And which column is the Name field actually in (is it field 3 or some other column)?
 
Upvote 0
Hi !

I have A to I with the name drop down being in G

H and I are for different comments and will not be autopopulated (in terms of repeating the previous data)
 
Upvote 0
Right-click on the sheet tab name at the bottom of the screen, select "View Code", and paste this code in the VB Editor window that pops up:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim r As Long

'   Exit if more than one cell updated at a time
    If Target.CountLarge > 1 Then Exit Sub
    
'   Get target row
    r = Target.Row
    
'   Only run if in column G under row 1
    If Target.Column = 7 And r > 1 Then
        Application.EnableEvents = False
'       Insert new row
        Rows(r + 1).Insert
'       Copy row above, from columns A - F
        Range(Cells(r, "A"), Cells(r, "F")).Copy Cells(r + 1, "A")
        Application.EnableEvents = True
    End If

End Sub
This should automatically do what you want, as you make a selection from column G.
 
Upvote 0
Solution
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,222,787
Messages
6,168,241
Members
452,171
Latest member
saeid025

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