Inquiridor
Salvando dados do List para planilha

Pergunta
-
Pessoal...
tá acontecendo algo inusitado aki...
quando eu tento salvar alguns dados do listbox em uma pasta de trabalho a parte (segue o codigo)
Private Sub cmdsalvarpendencia_Click() Dim j As Integer Dim i As Integer Dim linha As Integer Dim xl As New Excel.Application Dim xlw As Excel.Workbook Dim senha As String Dim var As Integer j = 1 If IsEmpty(ListBox1.Value) Then MsgBox "Clique em carregar as pendencias" Else linha = var + 1940 senha = InputBox("digite a senha para gravação") If senha = "senha" Then Set xlw = xl.Workbooks.Open("I:\pasta1\pasta2\pasta3\Controle .xls", , , , , "SENHA") xlw.Sheets("ANpend").Select For i = 16 To linha Step 1 xlw.Sheets("ANpend").Cells(i, 1) = ListBox1.List(j, 0) xlw.Sheets("ANpend").Cells(i, 2) = ListBox1.List(j, 1) xlw.Sheets("ANpend").Cells(i, 3) = ListBox1.List(j, 2) xlw.Sheets("ANpend").Cells(i, 4) = ListBox1.List(j, 3) xlw.Sheets("ANpend").Cells(i, 5) = "Análise de Falhas" xlw.Sheets("ANpend").Cells(i, 6) = "Rotina" xlw.Sheets("ANpend").Cells(i, 7) = ListBox1.List(j, 4) xlw.Sheets("ANpend").Cells(i, 8) = ListBox1.List(j, 5) xlw.Sheets("ANpend").Cells(i, 9) = ListBox1.List(j, 6) xlw.Sheets("ANpend").Cells(i, 10) = ListBox1.List(j, 7) xlw.Sheets("ANpend").Cells(i, 13) = ListBox1.List(j, 8) xlw.Sheets("ANpend").Cells(i, 12) = ListBox1.List(j, 9) j = j + 1 Next 'xlw.Save 'xlw.Close False 'Set xlw = Nothing 'Set xl = Nothing MsgBox "Concluido" Else MsgBox "senha invalida" End If End If
Leva cerca de 40 segundos pra inserir... porem quando eu faço assim (Segue o codigo)
Sub verificapendencias() Dim e As Integer Dim r As Integer Dim linhar As Integer Dim senha As String Dim varr As Integer e = 1 If IsEmpty(UserForm78.ListBox1.Value) Then MsgBox "Clique em carregar as pendencias" Else linhar = varr + 2016 senha = InputBox("digite a senha para gravação") If senha = "senha" Then Sheets("statuspend").Select For r = 16 To linhar Step 1 Sheets("statuspend").Cells(r, 1) = UserForm78.ListBox1.List(e, 0) Sheets("statuspend").Cells(r, 2) = UserForm78.ListBox1.List(e, 1) Sheets("statuspend").Cells(r, 3) = UserForm78.ListBox1.List(e, 2) Sheets("statuspend").Cells(r, 4) = UserForm78.ListBox1.List(e, 3) Sheets("statuspend").Cells(r, 5) = "Análise de Falhas" Sheets("statuspend").Cells(r, 6) = "Rotina" Sheets("statuspend").Cells(r, 7) = UserForm78.ListBox1.List(e, 4) Sheets("statuspend").Cells(r, 8) = UserForm78.ListBox1.List(e, 5) Sheets("statuspend").Cells(r, 9) = UserForm78.ListBox1.List(e, 6) Sheets("statuspend").Cells(r, 10) = UserForm78.ListBox1.List(e, 7) Sheets("statuspend").Cells(r, 13) = UserForm78.ListBox1.List(e, 8) Sheets("statuspend").Cells(r, 12) = UserForm78.ListBox1.List(e, 9) e = e + 1 MsgBox "Concluido" Else MsgBox "senha invalida" End End If End If End Sub
Demora minutos e mais minutos... alguem saberia porque?
obs... o segundo codigo ta salvando na propria planilha... o primeiro em uma a parte...