How to add series of rows based on quantity inputted

kdashsohel

New Member
Joined
Jul 27, 2017
Messages
9
Hello everyone,

I am fairly novice in terms of Macro and VBA. I work for immigration, and my supervisor had given me quite a huge task. I have a spreadsheet where I have to put information of a person's background and its family size. My problem is I am unable to figure out how to automatically create the number of rows once the family size has been inputted, also how to assign a number for each group of family created. For example below,
*(red means input, pink means automatic computerized input)*

## of FamilyFirst NameLast NameIDFamily Size
1DennisSmith1234
2KeithJohn456
3DamianDoe789

<tbody>
</tbody>

Then

## of FamilyFirst NameLast NameIDFamily Size
11DennisSmith1234
21
31
41
5KeithJohn456
6DamianDoe789

<tbody>
</tbody>

Then

## of FamilyFirst NameLast NameIDFamily Size
11DennisSmith1234
21JaneSmith741
31MarkSmith852
41JulieSmith963
5KeithJohn4561
6DamianDoe789

<tbody>
</tbody>
****** id="cke_pastebin" style="position: absolute; top: 0px; width: 1px; height: 1px; overflow: hidden; left: -1000px;">
## of FamilyFirst NameLast NameIDFamily Size
11DennisSmith1234
21
31
41
5KeithJoe456
6DamianDoe789

<tbody>
</tbody>
</body>
Then


## of FamilyFirst NameLast NameIDFamily Size
11DennisSmith1234
21JaneSmith741
31MarkSmith852
41JulieSmith963
5KeithJohn4561
6DamianDoe789

<tbody>
</tbody>

Then

## of FamilyFirst NameLast NameIDFamily Size
11DennisSmith1234
21JaneSmith741
31MarkSmith852
41JulieSmith963
5KeithJohn4561
6DamianDoe7892

<tbody>
</tbody>

Then



## of FamilyFirst NameLast NameIDFamily Size
11DennisSmith1234
21JaneSmith741
31MarkSmith852
41JulieSmith963
5KeithJohn4561
62DamianDoe7892
72MaryamDoe951

<tbody>
</tbody>


I am probably asking too much since I am new in this forum. Any help is greatly appreaciated.

*Note that my work environment involves two languages, English and French. I am working on an english computer station, but the majority of my colleagues are working in a french computer station. I am not sure if the VBA language will impact how excel works once shared in a different station.*

Once again thanks to anyone who is willing to take their time in helping me out!
 
Hello! Back in office, I tested this code and it worked! I understand this works on a basic test sheet, how can I put this on a more complex spreadsheet I have that consists of multiple different columns but 6 of the columns mentioned above is included in my spreadsheet.
 
Upvote 0

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
These are the names of the columns I have in my spreadsheet.

NumberDate of Inland Time of Inland Date application submtted at the POEFile numberLAST NAMEFirst nameHOFHOF numberIDCitizenship countryCountry of birthLanguage for interpretation1st official encountered at the borderProvince of destinationNot accompanied minor Referred to internallyCase processing Decision Deferred to investigation AGENTVISA USAVISA OBTAINEDPDE AT USARef Claim in US?US Ref Claim result?Interpreter RequiredOfficial LanguageDate of first contactDate of case completedNumber of person in familyNumber of FamilyFamily Size

<tbody>
</tbody>
 
Last edited:
Upvote 0
This should do it assuming your last column is AG and the Family Size (AG) is the only column that this needs to work on. Also, remember to change the AG1000 to however long you think the sheet might be.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
On Error GoTo errX
If Not Intersect(Target, Range("AG2:AG1000")) Is Nothing Then
    If Target.Value > 0 Then
        Application.EnableEvents = False
        Range("A" & Target.Row + 1 & ":AG" & Target.Row + 1).Resize(Target.Value - 1).Insert Shift:=xlDown
        Application.EnableEvents = True
    End If
End If
errX:
Application.EnableEvents = True
End Sub
 
Upvote 0
I've tried this, and it seems that it works. However, for example I added 2 for the family size, it only adds 2 extra rows across only 6 columns (A-F), not across the entire column I have in the spreadsheet (A-AG).
 
Upvote 0
I've tried this, and it seems that it works. However, for example I added 2 for the family size, it only adds 2 extra rows across only 6 columns (A-F), not across the entire column I have in the spreadsheet (A-AG).

Did you make the adjustments yourself or did you copy the new code in post #13 ? You need to change this part too:

Rich (BB code):
Range("A" & Target.Row + 1 & ":F" & Target.Row + 1).Resize(Target.Value - 1).Insert Shift:=xlDown

to

Rich (BB code):
Range("A" & Target.Row + 1 & ":AG" & Target.Row + 1).Resize(Target.Value - 1).Insert Shift:=xlDown
 
Upvote 0
Thank you very much for taking the time to reply me with patience. It is now working, I cannot express my gratitude enough for this.
 
Upvote 0
Thank you very much for taking the time to reply me with patience. It is now working, I cannot express my gratitude enough for this.

You're very welcome. I'm glad it's working for you. :)
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,930
Members
449,094
Latest member
teemeren

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