+ Reply to Thread
Results 1 to 9 of 9

Looping through a range

  1. #1
    Registered User
    Join Date
    08-07-2013
    Location
    Monroeville, Pa
    MS-Off Ver
    Excel 2010
    Posts
    22

    Looping through a range

    Hello, I'm fairly new to VBA and to this site. I've been able to accomplish somewhat simple macros, but this one is not cooperating with me.

    On my spreadsheet I have twelve ranges that represent every day in each month. Next to these ranges I have cells that I need to count occurrences within that month. I've been able to get this to work for the first item I need counted but I cannot get my loop to work. My ideal result would be to loop through each month and each reason performing the countif function. Any suggestions would be greatly appreciated. Can anyone assist?

    Here is the code I started with:

    Please Login or Register  to view this content.
    Sheet Example.xlsx
    Last edited by alansidman; 10-23-2013 at 07:24 PM. Reason: code tags added

  2. #2
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Looping through a range

    edp428,

    Welcome to the Excel Forum.

    Copy the below formula into range AG4:AQ15

    =COUNTIF($B4:$AF4,AG$3)


    See the attached workbook COUNTIF formula - edp428 - EF963411 - SDG15.xlsx
    Last edited by stanleydgromjr; 10-23-2013 at 06:28 PM.
    Have a great day,
    Stan

    Windows 10, Excel 2007, on a PC.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  3. #3
    Registered User
    Join Date
    08-07-2013
    Location
    Monroeville, Pa
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Looping through a range

    Thank you Stan but I am looking to complete this using VBA.

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2406 Win 11 Home 64 Bit
    Posts
    23,982

    Re: Looping through a range

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (I have added these for you this time. Please read our rules and abide by them in the future.)
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  5. #5
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,527

    Re: Looping through a range

    Hi edp428,

    Welcome to the forum!!

    Let us know how this goes, which is basically a VBA version of Stan's solution:

    Please Login or Register  to view this content.
    Regards,

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

  6. #6
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Looping through a range

    edp428,

    I am looking to complete this using VBA
    Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

    1. Copy the below code
    2. Open your NEW workbook
    3. Press the keys ALT + F11 to open the Visual Basic Editor
    4. Press the keys ALT + I to activate the Insert menu
    5. Press M to insert a Standard Module
    6. Where the cursor is flashing, paste the code
    7. Press the keys ALT + Q to exit the Editor, and return to Excel
    8. To run the macro from Excel press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

    Please Login or Register  to view this content.
    Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

    Then run the FillinFormulae macro.

  7. #7
    Registered User
    Join Date
    08-07-2013
    Location
    Monroeville, Pa
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Looping through a range

    Thank you, Robert, this worked beautifully!

  8. #8
    Registered User
    Join Date
    08-07-2013
    Location
    Monroeville, Pa
    MS-Off Ver
    Excel 2010
    Posts
    22

    Re: Looping through a range

    Thank you Stanley for this option also.

  9. #9
    Forum Expert
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2007
    Posts
    2,387

    Re: Looping through a range

    edp428,

    You are very welcome. Glad I could help.

+ 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. VBA Looping Input Range and Output Range
    By Whitley in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-25-2013, 12:04 PM
  2. Looping through rows in range AND comparing range cells
    By Damask in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-16-2006, 10:30 PM
  3. Determine if range has NO Blank Cells without looping through each cell in range
    By Excelenator in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-04-2006, 01:35 AM
  4. [SOLVED] Looping Range
    By JP in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-07-2006, 09:55 AM
  5. [SOLVED] Looping in a range
    By Robert in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-24-2006, 01:15 AM

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