Notifications
Clear all

Inserir a Data Via VBA

5 Posts
3 Usuários
0 Reactions
596 Visualizações
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

No Intervalo B14:E1012, preciso de função pra informar a Data Atual (Date) na Coluna E, desde que:
a) as colunas B, C e D sejam diferente de Vazio.
b) o Valor de B seja “Em Aberto”

Ex: Se B14 = "Em Aberto", e se C14 <> "", e se D14 <> "", então E14 = 04/02/2017

Precisa ser em VBA.

Grato,
Pedro

 
Postado : 04/02/2017 8:26 am
(@mprudencio)
Posts: 0
New Member
 

Tenta assim


Sub InserirData ()

Dim lin As Long

On Error Resume Next

lin = ActiveCell.Row

If Range("B" & lin).Value = "Em Aberto" _
And Range("C" & lin).Value <> "" _
And Range("D" & lin).Value <> "" Then

Range("E" & lin).Value = Date

End If

End Sub





 
Postado : 04/02/2017 10:24 am
(@brunoxro)
Posts: 0
New Member
 

Boa tarde Pedro,

Teste o código que está no módulo 1 do arquivo em anexo.

att,

 
Postado : 04/02/2017 10:41 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

MPrudencio,
O processo deve se repetir até a Última Célula Preenchida da Coluna B.
Como fazer?

 
Postado : 04/02/2017 11:03 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

brunoxro

Very Good, Amigo!
Obrigado!
Fiz uma pequena alteração:

Sub AtualizaDataVenda()
    
    Dim Nlin    As Double: Nlin = Range("B1048575").End(xlUp).Row
    Dim j       As Double

    'Da linha 1 até a última preenchida da coluna B
    For j = 1 To Nlin
        Application.EnableEvents = False
        
        Rem Cells(Linha,Coluna)
        
        'Se a célula da coluna B é Em Aberto, C e D são vazias
        If UCase(Trim(Cells(j, 2).Value)) = UCase(Trim("Em Aberto")) _
        And UCase(Trim(Cells(j, 3).Value)) <> Empty _
        And UCase(Trim(Cells(j, 4).Value)) <> Empty Then
            'Célula da coluna E recebe a data de hoje
            Cells(j, 5).Value = Date
        
        End If
        Application.EnableEvents = True
        
    Next j
   
End Sub
 
Postado : 04/02/2017 11:23 am