Rewritten Post of Adding Macros for Adding Rows

donnyray

New Member
Joined
Dec 26, 2015
Messages
4
My original Post was apparently confusing those trying to help me figure out this dilemma, so I am reposting a more broken down version of the post

I'm new to registering to this site but have used the related posts on the forums before but I can't seem to find something more specific to my needs. I am still new to using macros in Microsoft Excel so the coding is difficult for me to write.

I have values in column A that I use to add rows and the macro works for that need. The macro is as follows:

Sub Insert()
Dim End_Row As Long, n As Long, Ins As Long
End_Row = Range("A" & Rows.Count).End(xlUp).Row


For n = End_Row To 1 Step -1


Ins = Cells(n, 1).Value


If Ins > 1 Then Range("A" & n + 1 & ":A" & n + Ins).EntireRow.Insert


Next n
End Sub

Needed:

Example:
Column A Column B Column C Column D
# of Areas Name Title Areas
7 John Doe Area Manager *=offset formula*
******Insert 6 additional rows with populated formula in Column D in new rows and no longer adds additional rows

Problem 1:

Example:
Column A Column B Column C Column D
# of Areas Name Title Areas *Original Entry
8 John Doe Area Manager *=offset formula*
--Run Macro
******Insert 6 additional rows no formula

I have a formula in column D that I want to populate when the new rows are added.


Problem 2:

Example:
Column A Column B Column C Column D
# of Areas Name Title Areas *Original Entry
7 John Doe Area Manager *=offset formula*
--Run Macro
******Insert 6 additional rows no formula
******Inserts 6 more rows when running the macro for the entry below.
8 Jane Doe Area Manager *=offset formula* *New Entry After Original Macro Runs
******Insert 7 additional rows no formula


One problem I have is that if I have to add entries that need to have additional rows added with the macro, the Macro adds more rows to the entries that I already have the appropriate additional rows. How can I have the Macro ignore those entries? Is there a delimiter I can add for it to disregard those entries to not add additional rows to those entries?


I would greatly appreciate the help. Thanks.
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Change this section of code,

Code:
For n = End_Row To 1 Step -1
    Ins = Cells(n, 1).Value
    If Ins > 1 Then 
        Range("A" & n + 1 & ":A" & n + Ins).EntireRow.Insert
        [COLOR="#FF0000"]Cells(n,1).Value = 0[/COLOR]
    End If
Next n
It changes Cells(n,1) so the next time you press the button, the >1 test fails.
If you want to preserve the number for some other use, you might use Cells(n,1).Value = -1 * Ins, which is also not >1, but ABS will restore the data.
 
Upvote 0

Forum statistics

Threads
1,215,487
Messages
6,125,075
Members
449,205
Latest member
Healthydogs

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