Repeating code a set number of times

thefunkiestmunky

New Member
Joined
Oct 27, 2011
Messages
2
My first post! Be gentle :)

I've pretty much a novice at VBA but have managed to creat a task planner that does just what I need by copying code (mostly from here) so that I have an insert new row macro which puts in a new row, with the next ref, deleting the content but keeping the formulas and repating the conditional formula and sorting it all back in to date order with the selected cell on the new line I want to type in. So it's probably pretty messy code and I'd be hopeless as trying to change it significantly.

What I want to is insert x number of rows in bulk by entering the amount of rows I want in to a pop up box. The easiest way I can think of to do this is to loop the code the amount that I put in the pop up box but I can't find a code on the web that I can use or amend understand/easily enough.

If somebody could help me write a code to do this I would be eternally grateful! This is probably really basic I know...

e.g.

Code for pop up box to capture number of times
My code
Code to repeat it number of times entered
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
What I want to is insert x number of rows in bulk by entering the amount of rows I want in to a pop up box. The easiest way I can think of to do this is to loop the code the amount that I put in the pop up box but I can't find a code on the web that I can use or amend understand/easily enough.

If somebody could help me write a code to do this I would be eternally grateful! This is probably really basic I know...

e.g.

Code for pop up box to capture number of times
My code
Code to repeat it number of times entered
Hard to know how well this will fit in with your existing code, but a general structure like this should work for you...

Code:
Answer = Application.InputBox("How many times?", Type:=1)
For LoopCounter = 1 To Answer
  **Your Code Goes Here**
Next
where both the LoopCounter and Answer variables are Dim'med as Long (assuming you are declaring your variables).
 
Upvote 0
Thanks Rick. That does what I need but doesn't quite work with my last bit of code at the moment which is to put the next reference in the first cell of each line (e.g if I have 54 rows already it counts and labels it 55)... hopefully I'll be able to figure out why :eeek:
 
Upvote 0
Welcome to the Board!

When you have code questions and existing code, it's generally a good idea to post it. ;)
 
Upvote 0

Forum statistics

Threads
1,223,246
Messages
6,170,988
Members
452,373
Latest member
TimReeks

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