Consulting

Results 1 to 12 of 12

Thread: vba macro code for counting total days above 32 degrees, 33, 34, and goes on..

  1. #1
    VBAX Regular
    Joined
    Aug 2013
    Posts
    21
    Location

    vba macro code for counting total days above 32 degrees, 33, 34, and goes on..

    VBA MACRO CODE FOR COUNTING TOTAL DAYS ABOVE 32 DEG TEMP, 33, 34, AND GOES ON..

    Respected Sir /madam,
    I need VBA MACRO CODE for the following:
    from B,C columns i need totally how many days temp is 32 degrees and above, 33 degrees and above, 34 degrees and above, goes on.. i have did manually for your easy understanding. that is , from C column, in the given excel sheet it is 1922 days,out of 1922 days, 306 days has got 32 deg temp, 349 days has got 33 deg temp, goes on..

    important note: in C column we have decimal values also like 32. 5, 32.4, 32.7, 33.5, 33.9, 33.4, etc., which all must come under 32 and 33 category in the required output respectively. VALUES LESS THAN 32 AND ALL NO NEED.

    hope i m clear and not confusing... please find the attached excel sheet for your kind reference...

    please do help me... I need very urgently...please...

    Thanks & Regards,
    Dharani Suresh
    Attached Files Attached Files

  2. #2
    VBAX Regular raj85's Avatar
    Joined
    Feb 2010
    Location
    Mumbai
    Posts
    34
    Location
    It was really nice excersice for me.
    Please check code below:
    Goto VBE widow and add New module and use this code.

    Option Explicit
    Sub count_temp_days()
    Dim N As Integer, Temp As Byte
    Sheet1.Range("F6", Sheet1.Range("F6").End(xlToRight)).ClearContents
    N = 2
    While Sheet1.Range("A" & N).Value <> ""
        
        If Sheet1.Range("C" & N).Value >= 32 Then
            Temp = Evaluate("=rounddown(" & Sheet1.Range("C" & N).Value & ",0)")
            Sheet1.Range("E6").Offset(0, Temp - 31).Value = Sheet1.Range("E6").Offset(0, Temp - 31).Value + 1
        End If
        N = N + 1
    Wend
    End Sub
    You can do changes if you wish to.
    Last edited by raj85; 08-26-2013 at 01:28 AM. Reason: spell Correction

  3. #3
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Why not use a formula?
    F6=COUNTIF($C$2:$C$1923,">="&F5)

  4. #4
    VBAX Regular raj85's Avatar
    Joined
    Feb 2010
    Location
    Mumbai
    Posts
    34
    Location
    Dharani,

    Please mark this thred as resolved if you are satisfy with resolution provided.

  5. #5

    Post Alternative Solution

    You can do it this way too: In your workbook, access the VBE (alt+F11), create a new module and paste this:[VBA]Sub countdays()

    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual

    Dim i As Integer
    Dim j As Integer
    Dim somofdays As Integer


    For j = 6 To 25

    If Cells(5, j) = "" Then Exit For

    somofdays = 0

    For i = 2 To 2000

    If Cells(i, 3) = "" Then Exit For

    If Cells(i, 3) >= Cells(5, j) And Cells(i, 3) < Cells(5, j + 1) Then

    somofdays = somofdays + 1

    End If

    Next i

    Cells(6, j) = somofdays

    Next j

    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
    End Sub
    [/VBA]

  6. #6
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    Please turn off 'caps lock' when entering a thread title.
    Can you adapt the thread title into lowercase ?

  7. #7
    VBAX Regular
    Joined
    Aug 2013
    Posts
    21
    Location
    Quote Originally Posted by salmogomes View Post
    You can do it this way too: In your workbook, access the VBE (alt+F11), create a new module and paste this:[VBA]Sub countdays()

    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual

    Dim i As Integer
    Dim j As Integer
    Dim somofdays As Integer

    Application.Calculation = xlCalculationAutomatic
    End Sub
    [/VBA]

    Dear Salmogomes,
    Thank you so much for the quick response and my heartfelt thanks to you... thank you for the effort you made...

    Thanks & Regards,
    Dharani.

  8. #8
    VBAX Regular
    Joined
    Aug 2013
    Posts
    21
    Location
    Quote Originally Posted by raj85 View Post
    It was really nice excersice for me.
    Please check code below:
    Goto VBE widow and add New module and use this code.

    Option Explicit
    Sub count_temp_days()
    Dim N As Integer, Temp As Byte
    
        N = N + 1
    Wend
    End Sub
    Dear Raj85,
    Thank you so much for the quick response and my heartfelt thanks to you... thank you for the effort you made...

    Thanks & Regards,
    Dharani.

  9. #9
    VBAX Regular
    Joined
    Aug 2013
    Posts
    21
    Location
    Quote Originally Posted by snb View Post
    Please turn off 'caps lock' when entering a thread title.
    Can you adapt the thread title into lowercase ?

    ok done sir...

  10. #10
    VBAX Regular
    Joined
    Aug 2013
    Posts
    21
    Location
    Quote Originally Posted by raj85 View Post
    Dharani,

    Please mark this thred as resolved if you are satisfy with resolution provided.

    yes sir I will do that... thank you sir.....

  11. #11
    VBAX Regular
    Joined
    Aug 2013
    Posts
    21
    Location
    Quote Originally Posted by Kenneth Hobs View Post
    Why not use a formula?
    F6=COUNTIF($C$2:$C$1923,">="&F5)
    THANK YOU SIR....

  12. #12
    Quote Originally Posted by Dharani View Post
    Dear Salmogomes, Thank you so much for the quick response and my heartfelt thanks to you... thank you for the effort you made... Thanks & Regards,Dharani.
    You're welcome. We're here to help each others.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •