Esses macros e procedimentos do Aplicativo Microsoft Excel VBA(Visual Basic Application), usando o Evento Worksheet_Change, afeta a folha de planilha ativa ao digitar algo, neste caso escolhemos duas células (B5 e D5), ao digitar nestas células determinadas palavras o aplicativo abrirá um userform com algumas textbox vai inserir dados em determinadas colunas na folha de planilha. Espero que o exemplo lhe seja útil. Fique com Deus, Expedito Marcondes. '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - INSIRA O CÓDIGO ABAIXO NA FOLHA DE CÓDIGO DA FOLHA DE PLANILHA
Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address = "$B$5" And Target.Count = 1 Then
If Target.Value = "Motor" Then frmDADOS1.Show End If
ElseIf Targett.Address = "$D$5" And Target.Count = 1 Then
If Target.Value = "Ponte" Then frmDADOS2.Show End If
End If
End Sub
'- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - NO MODULO DE EDIÇÃO DO FORMULÁRIO frmDADOS1 INSIRA OS CÓDIGOS: Private Sub cmdLANCAR_Click() [O6:P1000].ClearContents 'limpar a area de inserção de novos dados.
Plan1.[O65000].End(xlUp).Offset(1, 0) = "Largura" Plan1.[O65000].End(xlUp).Offset(0, 1) = CDbl(txtLARGURA)
Plan1.[O65000].End(xlUp).Offset(1, 0) = "Comprimento.:" Plan1.[O65000].End(xlUp).Offset(0, 1) = CDbl(txtCOMPRIMENTO)
MsgBox ("Dados inseridos com sucesso"), vbInformation, "Saberexcel - o site das macros" End Sub
Private Sub cmdFECHAR_Click() Unload Me End Sub
Private Sub UserForm_Initialize() txtLARGURA.SetFocus End Sub '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
NO MODULO DE EDIÇÃO DO FORMULÁRIO frmDADOS2 INSIRA OS CÓDIGOS:
Private Sub cmdLANCAR_Click() [J6:K1000].ClearContents Plan1.[J65000].End(xlUp).Offset(1, 0) = "Potencia" Plan1.[J65000].End(xlUp).Offset(0, 1) = CDbl(txtPOTENCIA)
Plan1.[J65000].End(xlUp).Offset(1, 0) = "Tensão" Plan1.[J65000].End(xlUp).Offset(0, 1) = CDbl(txtTENSAO)
Plan1.[J65000].End(xlUp).Offset(1, 0) = "Rotação" Plan1.[J65000].End(xlUp).Offset(0, 1) = CDbl(txtROTACAO)
MsgBox ("Dados inseridos com sucesso"), vbInformation, "Saberexcel - o site das macros" End Sub
Private Sub UserForm_Initialize() txtPOTENCIA.SetFocus End Sub
Private Sub cmdFECHAR_Click() Unload Me End Sub
 Aprenda tudo sobre planilhas do Aplicativo Microsoft Excel VBA(Visual Basic Application), sozinho, com baixo custo, praticando com os produtos didáticos Escola Saberexcel VBA Estudos® - Treinamentos com Macros, Fórmulas e Funções.

|