Solved

Repeat an Excel macro multiple times

Posted on 2012-12-27
9
404 Views
Last Modified: 2012-12-28
I have the following macro in an Excel 2010 worksheet.  I need to repeat it about 25,000 times.  I know there's a loop feature that can be used, but I don't know enough about Visual Basic to get it to work.  And everything I find online is GREEK to me.  Can someone help me with the correct coding to get this done?  It would be greatly appreciated.  Thanks so much!!!!

Sub Move_Text3()
'
' Move_Text3 Macro
'

'
    ActiveCell.Range("A1:G1").Select
    Selection.Cut
    ActiveCell.Offset(-1, 8).Range("A1").Select
    ActiveSheet.Paste
    ActiveCell.Offset(3, -8).Range("A1").Select
End Sub
0
Comment
Question by:esu4236
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 48

Expert Comment

by:Martin Liss
ID: 38725319
Dim lngCount As Long

For lngCount = 1 to 25000

'Macro code

Loop
0
 

Author Comment

by:esu4236
ID: 38725332
I got a compile error:  Loop without Do.   ????????????  Here's the code now:

Sub Move_Text3()
'
' Move_Text3 Macro
'

'
Dim lngCount As Long

For lngCount = 1 To 5

    ActiveCell.Range("A1:G1").Select
    Selection.Cut
    ActiveCell.Offset(-1, 8).Range("A1").Select
    ActiveSheet.Paste
    ActiveCell.Offset(3, -8).Range("A1").Select
Loop

End Sub
0
 
LVL 48

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 38725531
I'm sorry, it's 'Next' not 'Loop'.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 48

Expert Comment

by:Martin Liss
ID: 38725551
What do you expect to have happen if you run that code more than once?
0
 

Author Comment

by:esu4236
ID: 38725775
I want it to go through and highlight some cells and then move them to the appropriate row.   There are lots of rows that need this done.
0
 
LVL 10

Expert Comment

by:tdlewis
ID: 38725851
As written, a loop would cause this code will move seven cells from every other row up one row (from where it started) and over eight cells.

For example, looping through that code three times would have this effect:
loop three timesIf that's truly what you need then adding the For loop (ending it with Next) as suggested by @MartinLiss will work.

If that's not what you need then describe what you're hoping to have happen.
0
 

Author Closing Comment

by:esu4236
ID: 38726865
Worked like a charm!!!!!!!!!  Thanks so much!!  I am amazed at how people know Visual Basic.  Wish I knew it much better than I do.  Thanks again.  Happy New Year!!!!!!!!!!!!
0
 
LVL 10

Expert Comment

by:tdlewis
ID: 38727197
@esu4236, the best way to learn VBA is to keep using it. Also, read the questions and answers on this site and you will learn a ton about interesting ways that other people are using it. I've learned a lot reading answers from other experts.
0
 
LVL 48

Expert Comment

by:Martin Liss
ID: 38727574
Glad I was able to help.

Marty - MVP 2009 to 2012
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question