View Single Post
  #1   Report Post  
tictox tictox is offline
Junior Member
 
Posts: 2
Default VBA Code Not Working

Hi. I am trying to find the flaw in my code. I've been staring at it for some time, and can't seem to figure it out. I am working with a spread sheet that someone else created. I am wondering if there is an excel quirk I am unaware of or if I am just missing my mistake. I am new to excel and vba.

Below is my code. I am getting 17 for a when I should be getting 18, but the total for all combined is correct. One of the 'a' values is being counted for misc.

Code:
Private Sub CommandButton1_Click()
    Dim misc    As Integer          
    Dim a     As Integer          
    Dim b   As Integer          
    Dim c As Integer          
    Dim d As Integer          
    Dim e     As Integer          
    
    Dim r As range
    
    'Create For-Each Loop to cycle through cells.
    For Each r In Worksheets("INPUT SHEET").range("F9:F335")
        If (UCase(r.Offset(0, -4).Value) < "CURED") Then
                Case "A"
                    a = a + 1
                    
                Case "AA"
                    a = a + 1
                    
                Case "AAA"
                    a = a + 1
                
                Case "B"
                    b = b + 1
                
                Case "C"
                    c = c + 1
            
                Case "D"
                    d = d + 1
            
                Case "E"
                    e = e + 1
                
                Case Else
                    If (r.Offset(0, -4).Value < "") Then
                        misc = misc + 1
                    End If
            End Select
        End If
    Next r     
    Worksheets("Summary").range("d10").Value = a
    Worksheets("Summary").range("d11").Value = b
    Worksheets("Summary").range("d12").Value = c
    Worksheets("Summary").range("d13").Value = d
    Worksheets("Summary").range("d14").Value = e
    Worksheets("Summary").range("d9").Value = misc
End Sub