Repeat an Excel macro multiple times

esu4236
esu4236 used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Martin LissYou can live to be a hundred if you give up all the things that make you want to be a hundred. - Woody Allen
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
Dim lngCount As Long

For lngCount = 1 to 25000

'Macro code

Loop

Author

Commented:
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
You can live to be a hundred if you give up all the things that make you want to be a hundred. - Woody Allen
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
I'm sorry, it's 'Next' not 'Loop'.
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Martin LissYou can live to be a hundred if you give up all the things that make you want to be a hundred. - Woody Allen
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
What do you expect to have happen if you run that code more than once?

Author

Commented:
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.

Commented:
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.

Author

Commented:
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!!!!!!!!!!!!

Commented:
@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.
Martin LissYou can live to be a hundred if you give up all the things that make you want to be a hundred. - Woody Allen
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
Glad I was able to help.

Marty - MVP 2009 to 2012

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial