Ajuda label e texto

gugadg

02-02-2015 17:48:18

Olá tenho essa planilha e estou com esse código. O que quer dele é simples. É colocar os valores inseridos na caixa de texto em uma planilha conforme for mudando o grupo escolhido num combobox terá uma coluna diferente. Depois de inserido preciso que retorne num label um frase analisando se o somatório da coluna do grupo é igual ou maior ou menor que outro somatório do grupo, se for maior preciso que além da frase vá o valor excedente. Não estou conseguindo fazer essa parte segue a planilha também.

Código: Selecionar todos

http://speedy.sh/VcK7W/EXEMPLO.xlsm

Código: Selecionar todos

Private Sub CommandButton1_Click()


If TextBox1.Value = "" Then
Exit Sub
End If

If ComboBox1.Value = "" Then
Exit Sub
End If

If ComboBox1.Value = "INTERLIGAÇÃO FRIGORÍFICA" Then
Dim varA As Variant
With Sheets("teste 1").Cells(Rows.Count, 1).End(xlUp)
.Offset(1, 0).Value = TextBox1.Text
End With
varA = Sheets("teste 1").Range("j7").Value

If varA < 0 Then
Label3.Caption = "Consumo dentro do orçado"
ElseIf varA = 0 Then
Label3.Caption = "Consumo dentro do orçado"
Else
varA > 0 then Label3.Caption = 6

End If
ComboBox1.ListIndex = -1
TextBox1.Text = ""
End If
End If
End Sub

Fabio Trindade

02-02-2015 18:16:05

Boa tarde, gugadg.

Não entendi muito bem sua duvida, mas segue a alteração no seu código:

Código: Selecionar todos

Private Sub CommandButton1_Click()

    If TextBox1.Value = "" Then
        Exit Sub
    End If
    
    If ComboBox1.Value = "" Then
        Exit Sub
    End If
    
    If ComboBox1.Value = "INTERLIGAÇÃO FRIGORÍFICA" Then
        Dim varA As Variant
        
        With Sheets("teste 1").Cells(Rows.Count, 1).End(xlUp)
            .Offset(1, 0).Value = TextBox1.Text
        End With
        
    varA = Sheets("teste 1").Range("j7").Value
    
    MsgBox varA
    
        If varA < 0 Then
            Label3.Caption = "Consumo dentro do orçado"
        ElseIf varA = 0 Then
            Label3.Caption = "Consumo dentro do orçado"
        ElseIf varA > 0 Then
            Label3.Caption = 6
        End If
    
    ComboBox1.ListIndex = -1
    TextBox1.Text = ""
    
    End If
    
End Sub

gugadg

02-02-2015 19:10:08

Fabio Trindade escreveu:Boa tarde, gugadg.

Não entendi muito bem sua duvida, mas segue a alteração no seu código:

Código: Selecionar todos

Private Sub CommandButton1_Click()

    If TextBox1.Value = "" Then
        Exit Sub
    End If
    
    If ComboBox1.Value = "" Then
        Exit Sub
    End If
    
    If ComboBox1.Value = "INTERLIGAÇÃO FRIGORÍFICA" Then
        Dim varA As Variant
        
        With Sheets("teste 1").Cells(Rows.Count, 1).End(xlUp)
            .Offset(1, 0).Value = TextBox1.Text
        End With
        
    varA = Sheets("teste 1").Range("j7").Value
    
    MsgBox varA
    
        If varA < 0 Then
            Label3.Caption = "Consumo dentro do orçado"
        ElseIf varA = 0 Then
            Label3.Caption = "Consumo dentro do orçado"
        ElseIf varA > 0 Then
            Label3.Caption = 6
        End If
    
    ComboBox1.ListIndex = -1
    TextBox1.Text = ""
    
    End If
    
End Sub
Vamos se agora melhora. O principal que preciso é o do label3. No caso quando varA>0 (varA é a diferença entre 2 dois valores na planilha, se olher está na plan "teste 1) preciso que tenha a mensagem Consumo além do orçado em "VarA".

Fabio Trindade

02-02-2015 19:42:20

Boa tarde, gugadg.

Da uma olhada nesse código:

Código: Selecionar todos

Private Sub CommandButton1_Click()

    If TextBox1.Value = "" Then
        Exit Sub
    End If
    
    If ComboBox1.Value = "" Then
        Exit Sub
    End If
    
    If ComboBox1.Value = "INTERLIGAÇÃO FRIGORÍFICA" Then
        Dim varA As Variant
        
        With Sheets("teste 1").Cells(Rows.Count, 1).End(xlUp)
            .Offset(1, 0).Value = TextBox1.Text
        End With
        
    varA = Sheets("teste 1").Range("L7").Value
    
        If varA <= 0 Then
            Label3.Caption = "Consumo dentro do orçado"
        
        ElseIf varA > 0 Then
            Label3.Caption = "Consumo além do orçado em " & Format(varA, "Currency")
        End If
    
    ComboBox1.ListIndex = -1
    TextBox1.Text = ""
    
    End If
    
End Sub

gugadg

03-02-2015 10:49:42

O código funcionou da maneira esperada. Mas fui repetir ele para outro grupo no caso "ELÉTRICA", mas ele na hora de escrever não pula a última a linha escrevendo por cima.Gostaria de saber como fazer o pulo, creio que o problema está no fato de a coluna a direita ter coisa escrita e ele começa direto na última linha desta.Segue o código como eu fiz.

Código: Selecionar todos

Private Sub CommandButton1_Click()

  If TextBox1.Value = "" Then
        Exit Sub
    End If
   
    If ComboBox1.Value = "" Then
        Exit Sub
    End If
   
    If ComboBox1.Value = "INTERLIGAÇÃO FRIGORÍFICA" Then
        Dim varA As Variant
       
        With Sheets("teste 1").Cells(Rows.Count, 1).End(xlUp)
            .Offset(1, 0).Value = TextBox1.Text
        End With
       
    varA = Sheets("teste 1").Range("L7").Value
   
        If varA <= 0 Then
            Label3.Caption = "Consumo dentro do orçado"
       
        ElseIf varA > 0 Then
            Label3.Caption = "Consumo além do orçado em " & Format(varA, "Currency")
        End If
   
    ComboBox1.ListIndex = -1
    TextBox1.Text = ""
   
    End If
  If ComboBox1.Value = "ELÉTRICA" Then
        Dim varB As Variant
       
        With Sheets("teste 1").Cells(Rows.Count, 1).End(xlUp)
            .Offset(1, 1).Value = TextBox1.Text
        End With
       
    varB = Sheets("teste 1").Range("L8").Value
   
        If varB <= 0 Then
            Label3.Caption = "Consumo dentro do orçado"
       
        ElseIf varB > 0 Then
            Label3.Caption = "Consumo além do orçado em " & Format(varB, "Currency")
        End If
   
    ComboBox1.ListIndex = -1
    TextBox1.Text = ""
   
    End If
   
   
End Sub

Fabio Trindade

05-02-2015 18:37:01

Boa tarde, gugadg.

Até onde eu entendi acho que seria mais ou menos assim que você queria fazer:
EXEMPLO.rar