Course Hive
Search

Welcome

Sign in or create your account

Continue with Google
or
Como criar Botão VBA para editar cadastro em uma Listbox
Play lesson

Curso de Excel Completo 2024 Basico ao Avançado ! - Como criar Botão VBA para editar cadastro em uma Listbox

5.0 (2)
29 learners

What you'll learn

This course includes

  • 19 hours of video
  • Certificate of completion
  • Access on mobile and TV

Summary

Keywords

Full Transcript

o script usado na aula Private Sub btnEditar_Click() Dim ws As Worksheet Dim selectedItemIndex As Integer Dim firstDataRow As Long Dim lastRow As Long ' Defina a planilha onde os dados estão armazenados (Planilha1) Set ws = ThisWorkbook.Sheets("Planilha1") ' Primeira linha com dados na planilha (começando da linha 2) firstDataRow = 2 ' Obtenha o índice do item selecionado na ListBox selectedItemIndex = ListBox1.ListIndex ' Verifique se algum item está selecionado If selectedItemIndex = -1 Then MsgBox "Por favor, selecione um item para editar.", vbExclamation Exit Sub End If ' Última linha preenchida na planilha lastRow = ws.Cells(ws.Rows.Count, 1).End(xlUp).Row ' Preencha os campos do UserForm com os valores correspondentes With Userform1 .txtcod.Value = ws.Cells(selectedItemIndex + firstDataRow, 1).Value .txtcell.Value = ws.Cells(selectedItemIndex + firstDataRow, 3).Value .txtnome.Value = ws.Cells(selectedItemIndex + firstDataRow, 2).Value .txtcep.Value = ws.Cells(selectedItemIndex + firstDataRow, 4).Value .txtcidade.Value = ws.Cells(selectedItemIndex + firstDataRow, 5).Value .txtbairro.Value = ws.Cells(selectedItemIndex + firstDataRow, 6).Value .txtuf.Value = ws.Cells(selectedItemIndex + firstDataRow, 7).Value .txtn.Value = ws.Cells(selectedItemIndex + firstDataRow, 8).Value .txtcomplemento.Value = ws.Cells(selectedItemIndex + firstDataRow, 9).Value .txtobs.Value = ws.Cells(selectedItemIndex + firstDataRow, 10).Value End With End Sub

Course Hive

Continue this lesson in the app

Install CourseHive on Android or iOS to keep learning while you move.

Related Courses

FAQs

Course Hive
Download CourseHive
Keep learning anywhere