PDA

View Full Version : Help in VBA problems with Macro



luisangy
03-14-2016, 04:23 AM
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

SamT
03-14-2016, 05:40 AM
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

SamT
03-14-2016, 05:47 AM
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. (http://www.vbaexpress.com/forum/showthread.php?55427-Bom-dia%21-Estou-com-um-problema-em-um-progama-de-comparacao-de-valores)