Validação de Dados

pedrobb

25-07-2012 23:41:20

Em uma seleção de células (B5:P5) uso a validação de dados para Não Permitir valores Repetidos: =NÃO(CONT.SE($B5:$P5;B5)>1)
Funciona muito Bem.

Agora preciso que o Intervalo aceite somente Valores de 01 a 99.

Pode ser por VBA ou Excel. Alguém pode ajudar?

Grato,
Pedro

Anonymous

27-07-2012 10:37:16

Bom dia Pedro
Usando a validação de Dados, em Permitir - Dados de Minimo até Máximo, não funciona?
Att.

joseA

27-07-2012 13:11:54

Código: Selecionar todos

Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
Application.EnableEvents = False

If Not Intersect(Target, Range("B5:P5")) Is Nothing Then
    If Target.Value < 1 Then 'de 01 a 99.
        MsgBox "Somente Valores de 01 a 99"
  
    End If
    If Target.Value > 99 Then
        MsgBox "Somente Valores de 01 a 99"
    End If
End If
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub

pedrobb

28-07-2012 11:37:36

JoseA,
Obrigado pela ajuda.

Tá dando conflito, pois já tenho a Worksheet_Change abaixo:

Private Sub Worksheet_Change(ByVal Target As Range)
If Not Range("A15") Is Nothing Then
If Range("a15") = "PARABÉNS!" Then
Alarme1
End If
If Range("a15") = "" Then
Sheets("Dados").Label2.Visible = False
End If

End If
End Sub

Dá prá juntar?
Outra coisa, gostaria que o foco voltasse para a célula com valor indevido.
Grato,
Pedro

joseA

28-07-2012 14:54:42

Tente:

Código: Selecionar todos

Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
Application.EnableEvents = False

If Not Intersect(Target, Range("B5:P5")) Is Nothing Then
    If Target.Value < 1 Then 'de 01 a 99.
        MsgBox "Somente Valores de 01 a 99"
        Target.Offset(0, 0).Select
        Target = ""
  
    End If
    If Target.Value > 99 Then
        MsgBox "Somente Valores de 01 a 99"
        Target.Offset(0, 0).Select
        Target = ""
    End If
End If


If Not Range("A15") Is Nothing Then
If Range("a15") = "PARABÉNS!" Then
'Alarme1
End If
If Range("a15") = "" Then
Sheets("Dados").Label2.Visible = False
Else
Sheets("Dados").Label2.Visible = True
End If

End If
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub

pedrobb

28-07-2012 15:54:24

Very Good!
Isso mesmo que eu precisava.
Obrigado, amigo.
Pedro

joseA

28-07-2012 23:58:00

Vlw ;)

pedrobb

04-06-2016 14:55:07

Pessoal,
Agora, no Intervalo B5:P14 preciso impedir a Digitação de Valores Repetidos nas Céluasl das Linhas (B5:P5, B6:P6........ até B14:P14).
Ao encontrar Valor Repetido, avisar com Mensagem de Erro.

Obs: No Excel, Em Validação de Dados, usava a fórmula: =NÃO(CONT.SE($B5:$P5;b5)>1).
Mas preciso do código pelo Vba.
Grato,

Pedro

pedrobb

11-06-2016 19:37:42

Com a ajuda de Osvaldomp e AlexandreVBA, ficou assim:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Or IsEmpty(Target(1, 1)) Then Exit Sub
If Intersect(Target, Range("B5:P14")) Is Nothing Then Exit Sub
If WorksheetFunction.CountIf(Range(Cells(Target.Row, 2), Cells(Target.Row, 16)), Target.Value) > 1 Then
MsgBox Target.Value & " Já existe"
Application.EnableEvents = False
Application.Undo
Application.EnableEvents = True
End If
End Sub