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
  • Avatar do usuário
#52516
Pessoal, estou precisando melhorar a rotina que executa um audio conforme cada célula é
preenchida com um valor determinado. segue abaixo um trecho da rotina que está funcionando só que gostaria de melhorar a rotina pois as condições serão muitas. Eu preciso que em 75 celulas seja testada uma por uma para cada 75 audios diferentes.

Private Sub Worksheet_Change(ByVal Target As Range)
If Planilha1.Range("A1") = 1 Then
PlayTheSound "B_01.wav"
End If

If Planilha1.Range("A1") = 2 Then
PlayTheSound "B_02.wav"
End If

If Planilha1.Range("A1") = 3 Then
PlayTheSound "B_03.wav"
End If

If Planilha1.Range("A1") = 4 Then
PlayTheSound "B_04.wav"
End If

If Planilha1.Range("A1") = 5 Then
PlayTheSound "B_05.wav"
End If

If Planilha1.Range("A1") = 6 Then
PlayTheSound "B_06.wav"
End If

If Planilha1.Range("A1") = 7 Then
PlayTheSound "B_07.wav"
End If

If Planilha1.Range("A1") = 8 Then
PlayTheSound "B_08.wav"
End If

If Planilha1.Range("A1") = 9 Then
PlayTheSound "B_09.wav"
End If

If Planilha1.Range("A1") = 10 Then
PlayTheSound "B_10.wav"
End If

If Planilha1.Range("A1") = 11 Then
PlayTheSound "B_11.wav"
End If

If Planilha1.Range("A1") = 12 Then
PlayTheSound "B_12.wav"
End If

If Planilha1.Range("A1") = 13 Then
PlayTheSound "B_13.wav"
End If

If Planilha1.Range("A1") = 14 Then
PlayTheSound "B_14.wav"
End If
End Sub
#52783
pirakaia,

Boa tarde!

Essa seria uma das formas de resolver o problema. Veja se pode ser assim.
Código: Selecionar todos
Private Sub Worksheet_Change(ByVal Target As Range)
    Application.EnableEvents = False
    Dim i As Long
    
    If Target.Count > 1 Then
        Application.EnableEvents = True
        Exit Sub
    End If
    
    If Target.Column = 1 Then
        For i = 1 To 75
            If Val(Plan1.Range("A1").Value) = i Then
                i = Str(i)
                Tocar_Som (i)
            End If
        Next i
    End If
    
    Application.EnableEvents = True
End Sub

Sub Tocar_Som(Num As String)
    PlayTheSound "B_" & Num & ".wav"
End Sub
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