+ Reply to Thread
Results 1 to 18 of 18

VBA loops

Hybrid View

  1. #1
    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,107

    Re: VBA loops

    In your example:

    C2: =COUNTA(B2:B366) = 365
    D2: =COUNTIF(B2:B366,0) = 317
    E2: =365-COUNTIF(B2:B366,0) = 48
    F2: =D2+E2 = 365

    If you drag these formulae down, they will give a 365 "rolling" total.

    Code to fill the range D2:D366

    With Range("D2:D366")
        .FormulaR1C1 = _
            "=COUNTIF(RC[-2]:R[364]C[-2],0)"
        .Value = .Value
    End With

    And column E:

    With Range("E2:E366")
        .FormulaR1C1 = _
            "=365-COUNTIF(RC[-3]:R[364]C[-3],0)"
        .Value = .Value
    End With


    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


  2. #2
    Registered User
    Join Date
    08-01-2012
    Location
    Birmigham, UK
    MS-Off Ver
    Excel 2007
    Posts
    10

    Re: VBA loops

    Thanks again,

    Where shall I put this code in the workbook and I am going through a data from 1942, which is the reason why I was more keen to use a VBA code.

    Regards,

    Malowle

+ 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