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.
  • Avatar do usuário
Por Adrian
Posts
#51637
Bom dia Pessoal!

Como faço para operar essa fórmula abaixO em código VBA. Quero transformá-la em macro. Como faço?. Me ajudem por favor?

EX: =SE(A1=4;"ADRIANO";SE(A1=3;"EVELLYN";SE(A1=2;"LIDIANE";SE(A1=1;"VANDERNILSON";))))

Grato
Avatar do usuário
Por JCabral
Avatar
#51640
Uma hipotese:
Código: Selecionar todos
Sub Teste_If()

    Select Case ActiveSheet.Range("A1")
    
        Case 1
           ActiveSheet.Range("B1") = "VANDERNILSON"
        
        Case 2
            ActiveSheet.Range("B1") = "LIDIANE"
        
        Case 3
            ActiveSheet.Range("B1") = "EVELLYN"
        
        Case 4
            ActiveSheet.Range("B1") = "ADRIANO"
1
        Case Else
            ActiveSheet.Range("B1") = ""
    
    End Select

End Sub

Por osvaldomp
#51655
Instale uma cópia do código abaixo no módulo da planilha.
Código: Selecionar todos
Private Sub Worksheet_Change(ByVal Target As Range)
 Dim Cx As Variant
  If Target.Address <> "$A$1" Then Exit Sub
  Cx = Array("VANDERNILSON", "LIDIANE", "EVELLYN", "ADRIANO") 
  [B1] = Cx([A1] - 1)
End Sub
Editado pela última vez por osvaldomp em 13 Jan 2020 às 15:04, em um total de 1 vez.
Avatar do usuário
Por JCabral
Avatar
#51656
osvaldomp escreveu:Instale uma cópia do código abaixo no módulo da planilha.
Código: Selecionar todos
Private Sub Worksheet_Change(ByVal Target As Range)
 Dim Cx As Variant
  If Target.Address <> "$A$1" Then Exit Sub
  Cx = Array("ADRIANO", "EVELLYN", "LIDIANE", "VANDERNILSON")
  [B1] = Cx([A1] - 1)
End Sub

O código é fantástico, apenas o array não está pela ordem pretendida.
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