+ Reply to Thread
Results 1 to 6 of 6

Make a loop in created macro

  1. #1
    Forum Contributor
    Join Date
    01-17-2011
    Location
    amsterdam, Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    189

    Make a loop in created macro

    Hi,

    I created a macro but I do not know how I can make a loop in the function?
    Hope someone can help me. I also attached my excel file


    Sub YEPP()

    If Not IsEmpty(Range("B2")) Then

    Range("B2:B8").Select
    Selection.Copy
    Range("B3").Select
    ActiveSheet.PasteSpecial Format:=3, Link:=1, DisplayAsIcon:=False, _
    IconFileName:=False

    Range("B2").Select
    Selection.ClearContents

    Range("B2").Select
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = "=TODAY()"
    Range("B2").Select
    Selection.Copy
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False

    Range("H2:H8", "I2:I8").Select
    Selection.Copy
    Range("H3", "I3").Select
    ActiveSheet.PasteSpecial Format:=3, Link:=1, DisplayAsIcon:=False, _
    IconFileName:=False

    Range("H2", "I2").Select
    Selection.ClearContents

    End If
    End Sub

    Function of the macro is that if there is a value in B2 then B2:B8 is copied to B3:B9, also value of day of today is inserted in B2
    value in B2 has to be deleted, H2:I8 copied to H3:I9, and values in H2:I2 are deleted.
    Next do the same thing in cell B10 look if there is a value in B10, ….
    Next do the same thing in cell B18…
    etc…
    Attached Files Attached Files
    Last edited by keis386; 06-08-2012 at 03:07 AM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,076

    Re: Make a loop in created macro

    Maybe:

    Please Login or Register  to view this content.

    regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor
    Join Date
    01-17-2011
    Location
    amsterdam, Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    189

    Re: Make a loop in created macro

    It works excellent thanks!

    Is there also a way to make a loop in my macro?

    Thanks a lot!

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,076

    Re: Make a loop in created macro

    That's what I've done. You need to introduce and increment variables (in a loop) ... which your macro is not doing. But you need to avoid selecting cells (or anything) because that will slow your macro down (and is unnecessary).


    Thanks for the rep.

    Regards, TMS

  5. #5
    Forum Contributor
    Join Date
    01-17-2011
    Location
    amsterdam, Netherlands
    MS-Off Ver
    Excel 2007
    Posts
    189

    Re: Make a loop in created macro

    Thanks a lot!

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,076

    Re: Make a loop in created macro

    You're welcome.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1