Consulting

Results 1 to 3 of 3

Thread: Help in VBA problems with Macro

  1. #1
    VBAX Newbie
    Joined
    Mar 2016
    Posts
    2
    Location

    Question Help in VBA problems with Macro

    Good morning everyone , I'm creating a progam that should compare a certain time of 2 columns in 2 different sheets , after comparing the values ​​the progam must follow the instrution. let's get to the problem : My variable B is not increasing the value (skipping to the next line) because she just does it when the value in variable B its bigger than the value of the variable A. I'm unable to compile it in progam . when I run the progam , only the variable returns the value ( because the for).

    Sub analisar()
    a = 6
    B = 7
    Menor = 0
    Maior = 0
    somaA = 6
    SomaB = 7
    ContA = Sheets("Boletim Produção").Cells(6, 42)
    ContB = Sheets("Boletim Parada").Cells(7, 4)
    
    For a = 6 To 5000
    
    
    If Sheets("Boletim Produção").Cells(a, 24) > Sheets("Boletim Parada").Cells(B, 3) Then
    
    Menor = ContA - 0.0007
    Maior = ContA + 0.0007
    
    If Menor < ContB And Maior > ContB Then
    
    
    ContA = ContA + Sheets("Boletim Produção").Cells(a + 1, 42)
    ContB = ContB + Sheets("Boletim Parada").Cells(B + 1, 4)
    Sheets("Boletim Produção").Cells(a, 42).Interior.Color = rgbGreen
    Sheets("Boletim Parada").Cells(B, 4).Interior.Color = rgbGreen
    Sheets("Boletim Produção").Cells(10, 47) = ContA
    a = a - 1
    B = B + 1
    
    Else
    If Sheets("Boletim Parada").Cells(B, 3) > Sheets("Boletim Produção").Cells(a, 24) And Sheets("Boletim Produção").Cells(a, 42) = 0 Then
    
    
    
    Sheets("Boletim Produção").Cells(a, 42).Interior.Color = rgbRed
    Sheets("Boletim Parada").Cells(B, 4).Interior.Color = rgbRed
    a = a - 1
    B = B + 1
    'ContA = Sheets("Boletim Produção").Cells(a, 42)
    'ContB = Sheets("Boletim Parada").Cells(B, 4)
    
    'Else
    'If Sheets("Boletim Produção").Cells(a, 42) = 0 Then
    'b = b + 1
    
    'ElseIf Sheets("Boletim Parada").Cells(b, 4) < Sheets("Boletim Produção").Cells(a, 24) Then
    'b = b + 1
    'a = a - 1
    
    
    
    'Else
    'Sheets("Boletim Produção").Cells(a, 42).Interior.Color = rgbRed
    'Sheets("Boletim Parada").Cells(b, 4).Interior.Color = rgbRed
    'End If
    
    Else
    Sheets("Boletim Produção").Cells(a, 42).Interior.Color = rgbGreen
    ContA = ContA + Sheets("Boletim Produção").Cells(a + 1, 42)
    
    
    End If
    End If
    End If
    
    Next
    End Sub

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    first problem I see
       ' For a = 5000  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<
          For a = 5000 to 6 Step - 1     '<<<<<<<<<<<<<<<<<<<<<<<<<<<
            If Sheets("Boletim Produção").Cells(a, 24) > Sheets("Boletim Parada").Cells(B, 3) Then 
                Menor = ContA - 0.0007 
                Maior = ContA + 0.0007 
                If Menor < ContB And Maior > ContB Then 
                    ContA = ContA + Sheets("Boletim Produção").Cells(a + 1, 42) 
                    ContB = ContB + Sheets("Boletim Parada").Cells(B + 1, 4) 
                    Sheets("Boletim Produção").Cells(a, 42).Interior.Color = rgbGreen 
                    Sheets("Boletim Parada").Cells(B, 4).Interior.Color = rgbGreen 
                    Sheets("Boletim Produção").Cells(10, 47) = ContA 
                    'a = a - 1 '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                    B = B + 1 
                     
                Else 
                    If Sheets("Boletim Parada").Cells(B, 3) > Sheets("Boletim Produção").Cells(a, 24) And Sheets("Boletim Produção").Cells(a, 42) = 0 Then 
                         
                         
                         
                        Sheets("Boletim Produção").Cells(a, 42).Interior.Color = rgbRed 
                        Sheets("Boletim Parada").Cells(B, 4).Interior.Color = rgbRed 
                        'a = a - 1 '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                        B = B + 1
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Duplicate thread, but I'm allowing it as it is in a second language.

    Also see thread:
    Bom dia! Estou com um problema em um progama de comparacao de valores.

    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Tags for this Thread

Posting Permissions

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