Este fórum está sendo desativado

Depois de 9 anos, este fórum será desativado. Mas calma.... estamos migrando para uma comunidade no DISCORD. Junte-se a nós.

ENTRAR PARA DISCORD

Tópicos relacionados a códigos VBA, gravação de macros, etc.
Por rcsj
#56684
Olá, meu conhecimento em VBA é praticamente zero e certa vez o precisei de um cogido para inserir uma data não volátil na célula do lado e os amigos do forum me ajudou bastante com o código abaixo, porém dessa vez estou precisando que na célula seguinte (que seria a Target.Offset(0, 2).Value) recebesse um valor de determinada célula da linha em questão, eu até consegui porém ela tá buscando sempre o valor da primeira linha de minha tabela, alguma dica?

Private Sub Worksheet_Change(ByVal Target As Range)
' Macro p/ inserir data atual não volátil em tabela nomeada
' 5 de setembro de 2016

On Error GoTo TrataErro

If Not Intersect(Target, Range("Tabela2[SITUAÇÃO]")) Is Nothing Then
If Target.Value = "RECEBIDO" Then
Target.Offset(0, 1).Value = Date
Else
Target.Offset(0, 1).Value = ""
Exit Sub
End If
End If


TrataErro:
' Sai da sub-rotina
Exit Sub
Por babdallas
#56706
Não entendi muito bem. Veja se ajuda.
Código: Selecionar todos
Private Sub Worksheet_Change(ByVal Target As Range)
    On Error GoTo TrataErro
    
    If Not Intersect(Target, Range("Tabela2[SITUAÇÃO]")) Is Nothing Then
        If Target.Value = "RECEBIDO" Then
            'Ajuste o Offset(, 4) para a célula que deseja
            Target.Offset(, 2).Value = Target.Offset(, 4).Value
        Else
            Target.Offset(, 2).Value = ""
            Exit Sub
        End If
    End If
    
    
TrataErro:
    ' Sai da sub-rotina
Exit Sub

Se não for isso, dê um exemplo prático explicando o resultado final.
Por rcsj
#56734
Olá babdallas,

em anexo está uma planilha modelo (quase como eu preciso), porém meu problema está sendo o seguinte, se na coluna SITUAÇÃO o valor escolhido for cartão 1x como mencionei no exemplo na coluna valor2 teria que aparecer o valor da primeira coluna correspondente a linha dela - como na planilha modelo está pegando sempre o valor da primeira linha

eu queria que aparecesse ( 100,00 - 150,00 - 257,00...)

a linha de código que tá é Target.Offset(0, 2).Value = Range("Tabela1[valor]").Value
Você não está autorizado a ver ou baixar esse anexo.
Por babdallas
#56735
Veja se é isso
Código: Selecionar todos
Private Sub Worksheet_Change(ByVal Target As Range)
    On Error GoTo TrataErro

    If Not Intersect(Target, Range("Tabela1[SITUAÇÃO]")) Is Nothing Then
        If Target.Value = "DINHEIRO" Then
            Target.Offset(, 1).Value = Date
        Else
            Target.Offset(, 1).Value = ""
        End If
        
        If Target.Value = "CARTÃO 1X" Then
            Target.Offset(, 3).Value = Date + 30
        Else
            Target.Offset(, 3).Value = ""
        End If
        
        If Target.Value = "CARTÃO 1X" Then
            Target.Offset(, 2).Value = Target.Offset(, -1).Value
        Else
            Target.Offset(, 2).Value = ""
        End If
        
        Exit Sub
    End If

TrataErro:

End Sub
Você não está autorizado a ver ou baixar esse anexo.
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]

Estamos migrando para uma comunidade no Discord