+ Reply to Thread
Results 1 to 6 of 6

Counter and a Loop

  1. #1
    Registered User
    Join Date
    07-27-2018
    Location
    Sofia, Bulgaria
    MS-Off Ver
    2013
    Posts
    13

    Counter and a Loop

    Hello Fellow Forum Members,

    I'm a beginner in Excel VBA and need help how to create a loop and count occurrencies of particular values. I have a list of machines and the materials they are made of.I'm interested how many machines are made of "Wood". Attached is the sample file. I have difficulty deciding how many varialbles I need (what for) and how to write the loop. I suppose that a Do until loop is a solution but I'm not getting it correctly.

    Could you please give ideas how to get the result of the counter in a messagebox?

    Kind regards,
    Nevena
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: Counter and a Loop

    Quote Originally Posted by bnevena View Post
    I have a list of machines and the materials they are made of.I'm interested how many machines are made of "Wood".
    You don't need a VBA for this. This can be achieved by using builtin function "CountIF". Did you try that?
    Teach me Excel VBA

  3. #3
    Registered User
    Join Date
    07-27-2018
    Location
    Sofia, Bulgaria
    MS-Off Ver
    2013
    Posts
    13

    Re: Counter and a Loop

    Hello ImranBhatti,
    I'm exercising VBA and that's why I'm searching for a way to solve this challenge with a loop and counter.

  4. #4
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: Counter and a Loop

    In cell E1 type "Steel" or "Wood" and run this code.

    PHP Code: 
    Sub CountForMaterial()
    Dim i As IntegerAs Integer

    0
    With Sheet1
        
    For 2 To .Range("C" Rows.Count).End(xlUp).Row
            
    If .Cells(i3) = .Cells(15Then
                j 
    1
            End 
    If
        
    Next i
    End With
    MsgBox j
    End Sub 
    For further learning visit here.l

  5. #5
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,078

    Re: Counter and a Loop

    Another option
    Please Login or Register  to view this content.

  6. #6
    Valued Forum Contributor ImranBhatti's Avatar
    Join Date
    03-27-2014
    Location
    Rawalpindi,Pakistan
    MS-Off Ver
    Office 365
    Posts
    1,784

    Re: Counter and a Loop

    Thanks for the rep+

+ 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 Reference a Loop Counter
    By Bensley in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-18-2018, 03:19 AM
  2. Display a loop counter
    By TBurgum in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-12-2018, 04:10 PM
  3. [SOLVED] Reducing the value of a loop counter
    By danielexcelvba in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-08-2017, 12:29 PM
  4. Loop Macro with Counter
    By Ricky Wilko in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-18-2014, 07:33 AM
  5. For loop counter reset
    By amphinomos in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-03-2014, 10:59 AM
  6. [SOLVED] Counter in a loop
    By jonathanrgz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-11-2013, 05:46 PM
  7. How can I avoid changing a loop counter within a loop?
    By broro183 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-26-2009, 07:59 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