Fórum para dúvidas sobre os fundamentos da linguagem de programação Visual Basic no contexto do VBA
McJota
Colaborador
Mensagens: 26 Registrado em: Sáb Out 13, 2012 10:16 pm
Mensagem
por McJota » Dom Out 21, 2012 5:55 am
Olá pessoal.
Tem como simplificar essa macro?
Código: Selecionar todos
TextBox17.Value = ActiveCell.Offset(0, 1).Value
TextBox18.Value = ActiveCell.Offset(1, 1).Value
TextBox19.Value = ActiveCell.Offset(2, 1).Value
TextBox20.Value = ActiveCell.Offset(3, 1).Value
TextBox21.Value = ActiveCell.Offset(4, 1).Value
TextBox22.Value = ActiveCell.Offset(5, 1).Value
TextBox23.Value = ActiveCell.Offset(6, 1).Value
TextBox24.Value = ActiveCell.Offset(7, 1).Value
TextBox25.Value = ActiveCell.Offset(8, 1).Value
TextBox26.Value = ActiveCell.Offset(9, 1).Value
TextBox27.Value = ActiveCell.Offset(10, 1).Value
TextBox28.Value = ActiveCell.Offset(11, 1).Value
TextBox29.Value = ActiveCell.Offset(12, 1).Value
TextBox30.Value = ActiveCell.Offset(13, 1).Value
Obrigado...
Editado pela última vez por
McJota em Seg Out 22, 2012 4:04 pm, em um total de 1 vez.
This site is supported by ads and donations. If you see this text you are blocking our ads. Please consider a Donation to support the site.
BaptistaCG
Colaborador
Mensagens: 96 Registrado em: Seg Jul 30, 2012 10:33 pm
Localização: Sorocaba/SP
Mensagem
por BaptistaCG » Seg Out 22, 2012 10:57 am
Vish esse eu não consegui nada ainda. rsrs
Eu consigo simplificar o .offset usando laço mas o textbox tá dificil, mas se eu conseguir algo lhe dou um toque.
Abraço.
Att.
Vega
Colaborador
Mensagens: 26 Registrado em: Sáb Ago 18, 2012 7:46 pm
Mensagem
por Vega » Seg Out 22, 2012 12:23 pm
Jota,
Segue a macro simplificada.
Caso os únicos textbox do formulário sejam esses, de 17 a 30, dá para tirar a estrutura If Right(Controle.Name, 2)
Código: Selecionar todos
Dim Controle As Object
Dim intLinha As Integer
intLinha = 0
For Each Controle In Me.Controls
If TypeName(Controle) = "TextBox" Then
If Right(Controle.Name, 2) >= 17 Then
Controle.Value = ActiveCell.Offset(intLinha, 1).Value
intLinha = intLinha + 1
End If
End If
Next Controle
McJota
Colaborador
Mensagens: 26 Registrado em: Sáb Out 13, 2012 10:16 pm
Mensagem
por McJota » Seg Out 22, 2012 2:44 pm
olá Vinicius E Vega.
Obrigado pela atenção!
Consegui simplificar com o seguinte código:
Código: Selecionar todos
Dim I As Integer
For I = 0 To 13
Me.Controls("TextBox" & (I + 17)).Value = ActiveCell.Offset(I, 1).Value
Next I
Abraço....
This site is supported by ads and donations. If you see this text you are blocking our ads. Please consider a Donation to support the site.
BaptistaCG
Colaborador
Mensagens: 96 Registrado em: Seg Jul 30, 2012 10:33 pm
Localização: Sorocaba/SP
Mensagem
por BaptistaCG » Seg Out 22, 2012 7:53 pm
McJota escreveu: olá Vinicius E Vega.
Obrigado pela atenção!
Consegui simplificar com o seguinte código:
Código: Selecionar todos
Dim I As Integer
For I = 0 To 13
Me.Controls("TextBox" & (I + 17)).Value = ActiveCell.Offset(I, 1).Value
Next I
Abraço....
Ótimo, tudo certo então, mas eu não consegui fazer funcionar aqui, eu tinha deixado tudo como o primeiro exemplo e estava funcionando normal, mas agora não deu não.
Valeu..
Até mais.
Att...
This site is supported by ads and donations. If you see this text you are blocking our ads. Please consider a Donation to support the site.