+ Reply to Thread
Results 1 to 6 of 6

How to make a macro run for each cell in a loop for the active range

  1. #1
    Registered User
    Join Date
    11-27-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    12

    How to make a macro run for each cell in a loop for the active range

    Hi

    I have three columns

    Name Grade Number
    Jack A 1
    John B 2
    Jill C 3
    David D 4
    Harry E 5
    Tom F 6

    I want to make the number zero for all selected cells.

    For example. Say I select Jack and John OR A and B. I want to make the numbers 1 and 2 as zero.

    I currently know how to do if only one cell is selected. But what if a range of cells is selected?

    How do I loop the macro to run for each cell in active range. I have attached the excel file with a macro for further clarification. I want that code to loop for all cells in active range.

    New Microsoft Excel Worksheet.xlsm

    Please assume I don't know the boundaries of the active range. There can be three rows, four rows or even ten rows.

    I have tried the following code. However that makes all the numbers in the "Number" column zero. I just want the active rows numbers to become zero.

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: How to make a macro run for each cell in a loop for the active range

    Try this...

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    11-27-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: How to make a macro run for each cell in a loop for the active range

    It worked thanks. But could you tell me if it is possible for me to do the same where instead of assigning zero, I run another macro where I pass the cell address as an argument. For example Macro_2("A2") ? I sort of assumed that if I figured this out, I could easily figure that out as well lol. But sadly I am not able to.

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: How to make a macro run for each cell in a loop for the active range

    Quote Originally Posted by alrikvincent View Post
    It worked thanks. But could you tell me if it is possible for me to do the same where instead of assigning zero, I run another macro where I pass the cell address as an argument. For example Macro_2("A2") ? I sort of assumed that if I figured this out, I could easily figure that out as well lol. But sadly I am not able to.
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    11-27-2012
    Location
    India
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: How to make a macro run for each cell in a loop for the active range

    Thanks AlphaFrog. It worked.

  6. #6
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: How to make a macro run for each cell in a loop for the active range

    You're welcome.

    Mark this as solved.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. How to make macro start at the Active cell
    By livemusic in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-15-2013, 02:02 PM
  2. Macro Button: To paste selected range into active cell
    By Grundy_03 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-29-2012, 07:41 PM
  3. In VB macro how do I select range from active cell
    By spydor in forum Excel General
    Replies: 5
    Last Post: 12-29-2005, 07:15 PM
  4. Replies: 3
    Last Post: 11-18-2005, 05:00 PM
  5. Macro Copy Active Cell to Range Name, loop
    By zigstick in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-27-2005, 03:06 PM

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