+ Reply to Thread
Results 1 to 7 of 7

Using Loops for Repetitive Task

  1. #1
    Registered User
    Join Date
    10-10-2010
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    9

    Using Loops for Repetitive Task

    Hi I'm very new to VBA and am learning. I recorded a macro as below. Can it be simplified using a Loop function somehow? I would like to loop until Column A is empty. Thank you. Felix

    Please Login or Register  to view this content.
    Last edited by fa888; 10-20-2010 at 02:14 AM. Reason: I violated forum rules regarding code/tags and title description.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Can anyone simplify this?

    Your post does not comply with Rule 1 of our Forum RULES. Your post title should accurately and concisely describe your problem, not your anticipated solution. Use terms appropriate to a Google search. Poor thread titles, like Please Help, Urgent, Need Help, Formula Problem, Code Problem, and Need Advice will be addressed according to the OP's experience in the forum: If you have less than 10 posts, expect (and respond to) a request to change your thread title. If you have 10 or more posts, expect your post to be locked, so you can start a new thread with an appropriate title.
    To change a Title on your post, click EDIT then Go Advanced and change your title, if 2 days have passed ask a moderator to do it for you.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    10-10-2010
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Using Loops for Repetitive Task

    Thank you RoyUK for pointing out my violations. I hope I meet the forum rules this time. Felix

  4. #4
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Using Loops for Repetitive Task

    This will give you a start
    Please Login or Register  to view this content.
    You can plug what you've selected directly into Sheets("analysis") without having to selecting it. Kind of like how I changed the first two lines of your code.

    Also it will run faster if you set ScreenUpdating to false.

    If you need to find the last row in A look at
    http://www.mrexcel.com/td0058.html

    You would use code like this:

    Please Login or Register  to view this content.
    hth

  5. #5
    Registered User
    Join Date
    10-10-2010
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Using Loops for Repetitive Task

    Thanks MarvinP, I tried your code and put in 1 line that was missing in my recorded macro. That's to copy value of cell BF22.

    Please Login or Register  to view this content.
    This code did not return to required result and I believe it is because I did not explain the situation clearly. I have attached a jpeg of the worksheets to describe what was intended.

    The purpose is to fill up column C in PAIRS worksheet from Analysis!BF22.

    (As a background, I have 45 people in my group and through the years they have paired up as a team. I am trying to get a summary of who paired with whom and how many times it happened).

    Thanks. Felix
    Attached Images Attached Images

  6. #6
    Registered User
    Join Date
    10-10-2010
    Location
    Australia
    MS-Off Ver
    Excel 2003
    Posts
    9

    Re: Using Loops for Repetitive Task

    MarvinP, I worked on your Rowctr hint and got it to work exactly the way I wanted. That's after recording many many macros and seeing how the macros work and looking at your hint. Thank you v much.

    Regrettably, I don't know what Rowctr stands for. Is it Row - center?

    In any case, the end result that worked is

    Please Login or Register  to view this content.

  7. #7
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,167

    Re: Using Loops for Repetitive Task

    RowCtr is a variable that I create to tell me it is a "Row Counter".
    I use it in loops to run down the rows.

    ColCtr is my variable name to count columns or Column Counter.
    Other people have their own styles of variable naming.

    When I read code (including my own code) it is hard to remember what all those variables mean. I try to give them a name that tells what they are or what they do. Another favorite variable is LastRow.

    If you start naming your variables in a way that makes sense you will be able to read you code much easier.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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