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
Por AMORIM123
Posts Avatar
#33305
Salve, salve galera do fórum.

No "cód. do "frm_rbpa" abaixo tenho um evento que pretendo chamar dentro do evento UserForm_Initialize(), porém ao executar para ver se rodar legal, da "tipo incompatíveis"; se depuro o cód. ele grifa a linha : "datPeriodo = .txt_periodo.Text"

Código: Selecionar todos
Private Sub txt_periodo_AfterUpdate()

Dim lngPriLin, lngUltLin, lngLoopLin       As Long
Dim datPeriodo                             As Date
Dim vlrRPA, vlrFSPA                        As Currency
Dim strbusca                               As String

lngPriLin = 2

With Me
'linha grifada
datPeriodo = .txt_periodo.Text
vlrRPA = .txt_rpa.Text
vlrFSPA = .txt_fspa.Text
End With

With wshComum
    lngUltLin = .Cells(.Rows.Count, 2).End(xlUp).Row
End With

With wshComum
    For lngLoopLin = lngPriLin To lngUltLin Step 1
        strbusca = .Cells(lngLoopLin, 2)

        If strbusca = datPeriodo Then
            .Cells(lngLoopLin, 3) = CCur(vlrRPA)
            .Cells(lngLoopLin, 4) = CCur(vlrFSPA)
        End If
   Next lngLoopLin
End With

End Sub
Código: Selecionar todos
Private Sub UserForm_Initialize()

Call txt_periodo_AfterUpdate
     
End Sub
A quem puder ajudar agradeço!
Você não está autorizado a ver ou baixar esse anexo.
Por babdallas
#33307
Já que sua variável é do tipo Date, então tente o seguinte:
Código: Selecionar todos
datPeriodo = VBA.Cdate(.txt_periodo.Value)
Avatar do usuário
Por AMORIM123
Posts Avatar
#33308
babdallas,

não especifiquei meu objetivo com código assim: meu objetivo com evento "afterupdate ": é fazer com que quando digitada uma data que esteja na planilha (Comum) e ao mudar o foco do "txtbox_periodo" os demais sejam preenchidas com os demais dados da mesma linha do registro

fiz algumas alterações e o erro de tipos incompatíveis não está dando mais, porém o objetivo não está sendo executado, veja como está:
Código: Selecionar todos
Private Sub txt_periodo_AfterUpdate()

Dim lngPriLin, lngUltLin, lngLoopLin       As Long
Dim datPeriodo                             As Date
Dim vlrRPA, vlrFSPA                        As Currency
Dim strbusca                               As String


If txt_Peridodo = "" Or IsEmpty(txt_periodo) Then Exit Sub
If txt_rpa = "" Or IsEmpty(txt_rpa) Then Exit Sub
If txt_fspa = "" Or IsEmpty(txt_fspa) Then Exit Sub

lngPriLin = 2


datPeriodo = CDate(txt_periodo.Text)
vlrRPA = txt_rpa.Text
vlrFSPA = txt_fspa.Text


With wshComum

    lngUltLin = .Cells(.Rows.Count, 2).End(xlUp).Row

    For lngLoopLin = lngPriLin To lngUltLin Step 1
        strbusca = .Cells(lngLoopLin, 2)

        If strbusca = datPeriodo Then
            vlrRPA = .Cells(lngLoopLin, 3)
            vlrFSPA = .Cells(lngLoopLin, 4)
        End If
   Next lngLoopLin
End With

End Sub
Você não está autorizado a ver ou baixar esse anexo.
Avatar do usuário
Por AMORIM123
Posts Avatar
#33329
O babdallas,

Vlw amigão pela ateção... lá planilhando srobles ajudou-me:

Solução ficou assim:
Código: Selecionar todos
Private Sub txt_periodo_AfterUpdate()

Dim lngPriLin, lngUltLin, lngLoopLin       As Long
Dim datPeriodo                             As Date
Dim strbusca                               As String
    
    lngPriLin = 2
    
    With Me
        On Error GoTo trataErro
        datPeriodo = .txt_periodo.Text
    End With
    
    With wshComum
        lngUltLin = .Cells(.Rows.Count, 2).End(xlUp).Row
    End With
    
    With wshComum
        For lngLoopLin = lngPriLin To lngUltLin Step 1
            strbusca = .Cells(lngLoopLin, 2)
    
            If strbusca = datPeriodo Then
                Me.txt_rpa = CCur(.Cells(lngLoopLin, 3))
                Me.txt_fspa = CCur(.Cells(lngLoopLin, 4))
                Exit For
            End If
        Next lngLoopLin
    End With
trataErro:
If Err.Number = 13 Then
    Me.txt_periodo = ""
    Me.txt_rpa = ""
    Me.txt_fspa = ""
End If

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