Notifications
Clear all

Erro: End With sem With *Mas tem!

7 Posts
2 Usuários
0 Reactions
1,873 Visualizações
(@finaljustice)
Posts: 91
Estimable Member
Topic starter
 

Boa tarde,
Então está ocorrendo esse erro, mas o WITH está acompanhado de END WITH "bonitinho"... Deve ser um problema bem besta.
Não sei se posso estar usando o WITH da maneira que estou... tipo duas vezes. Na minha cabeça n deveria fazer diferença pois se estou "fechando" o with com end with...

Sub clockit()
If UserForm1.CommandButton1.Caption = "Clock-in" And UserForm1.ComboBox1 <> "" Then

            With ThisWorkbook.Worksheets("Control")
            lastentry = .Range("D" & .Cells(.Rows.Count, 1).End(xlUp).Row + 1).Address
            .Range(lastentry).Value = UserForm1.TextBox4.Text
            .Range(lastentry).Offset(0, -2) = UserForm1.TextBox2.Text
            .Range(lastentry).Offset(0, -3) = UserForm1.TextBox1.Text
            .Range(lastentry).Offset(0, -1) = UserForm1.ComboBox1.Text
            UserForm1.CommandButton1.Caption = "Clock-out"
            Set Rng = .Range("A2:F" & .Cells(Rows.Count, 1).End(xlUp).Row)
                
                For Each cell In Rng.Cells
                With UserForm1.ListBox1
                    .AddItem cell.Value
                    .List(.ListCount - 1, 1) = cell.Offset(0, 1).Value
                    .List(.ListCount - 1, 2) = cell.Offset(0, 2).Value
                    .List(.ListCount - 1, 3) = cell.Offset(0, 3).Value
                    .List(.ListCount - 1, 4) = cell.Offset(0, 4).Value
                    .List(.ListCount - 1, 5) = cell.Offset(0, 5).Value
                    .List(.ListCount - 1, 6) = cell.Offset(0, 6).Value
                End With
            End With
            
    
ElseIf UserForm1.CommandButton1.Caption = "Clock-out" And UserForm1.ComboBox1 <> "" Then
        With ThisWorkbook.Worksheets("Control")
        .Range(lastentry).Offset(0, 1) = UserForm1.TextBox4.Text
        UserForm1.CommandButton1.Caption = "Clock-in"
        UserForm1.ComboBox1 = Empty
        Set Rng = .Range("A2:F" & .Cells(Rows.Count, 1).End(xlUp).Row)
                
                For Each cell In Rng.Cells
                With UserForm1.ListBox1
                    .AddItem cell.Value
                    .List(.ListCount - 1, 1) = cell.Offset(0, 1).Value
                    .List(.ListCount - 1, 2) = cell.Offset(0, 2).Value
                    .List(.ListCount - 1, 3) = cell.Offset(0, 3).Value
                    .List(.ListCount - 1, 4) = cell.Offset(0, 4).Value
                    .List(.ListCount - 1, 5) = cell.Offset(0, 5).Value
                    .List(.ListCount - 1, 6) = cell.Offset(0, 6).Value
                End With
            End With
            
       
        End With

End If

End Sub

Antes de aparecer o erro estava tudo funcionando, eu quis dar uma avançada para popular o listbox da userform, o código antes funcionava:

Sub clockit()
If UserForm1.CommandButton1.Caption = "Clock-in" And UserForm1.ComboBox1 <> "" Then

            With ThisWorkbook.Worksheets("Control")
            lastentry = .Range("D" & .Cells(.Rows.Count, 1).End(xlUp).Row + 1).Address
            .Range(lastentry).Value = UserForm1.TextBox4.Text
            .Range(lastentry).Offset(0, -2) = UserForm1.TextBox2.Text
            .Range(lastentry).Offset(0, -3) = UserForm1.TextBox1.Text
            .Range(lastentry).Offset(0, -1) = UserForm1.ComboBox1.Text
            UserForm1.CommandButton1.Caption = "Clock-out"
           
            End With
         
ElseIf UserForm1.CommandButton1.Caption = "Clock-out" And UserForm1.ComboBox1 <> "" Then
        With ThisWorkbook.Worksheets("Control")
        .Range(lastentry).Offset(0, 1) = UserForm1.TextBox4.Text
        UserForm1.CommandButton1.Caption = "Clock-in"
        UserForm1.ComboBox1 = Empty
        
        End With
 End If

End Sub

Alguém poderia me dar uma ajuda?
Obrigado pela atenção e tempo!
Att,

Luis

Um problema a parte, eu não estou recebendo emails de aviso de resposta para mensagens aqui no forum... meu email está correto, e estou deixando marcado para "Notificar-me quando for respondida".

 
Postado : 27/01/2015 1:50 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Boa tarde!!

Se você indentar seu código verá que esse é error deriva de uma sobra End With sem With, se for depurando, há outros :lol:

Sub clockit()
If UserForm1.CommandButton1.Caption = "Clock-in" And UserForm1.ComboBox1 <> "" Then
    With ThisWorkbook.Worksheets("Control")
        lastentry = .Range("D" & .Cells(.Rows.Count, 1).End(xlUp).Row + 1).Address
        .Range(lastentry).Value = UserForm1.TextBox4.Text
        .Range(lastentry).Offset(0, -2) = UserForm1.TextBox2.Text
        .Range(lastentry).Offset(0, -3) = UserForm1.TextBox1.Text
        .Range(lastentry).Offset(0, -1) = UserForm1.ComboBox1.Text
         UserForm1.CommandButton1.Caption = "Clock-out"
         Set Rng = .Range("A2:F" & .Cells(Rows.Count, 1).End(xlUp).Row)
            For Each cell In Rng.Cells
                With UserForm1.ListBox1
                    .AddItem cell.Value
                    .List(.ListCount - 1, 1) = cell.Offset(0, 1).Value
                    .List(.ListCount - 1, 2) = cell.Offset(0, 2).Value
                    .List(.ListCount - 1, 3) = cell.Offset(0, 3).Value
                    .List(.ListCount - 1, 4) = cell.Offset(0, 4).Value
                    .List(.ListCount - 1, 5) = cell.Offset(0, 5).Value
                    .List(.ListCount - 1, 6) = cell.Offset(0, 6).Value
                End With
                'Fim do Laço
ElseIf UserForm1.CommandButton1.Caption = "Clock-out" And UserForm1.ComboBox1 <> "" Then
        With ThisWorkbook.Worksheets("Control")
            .Range(lastentry).Offset(0, 1) = UserForm1.TextBox4.Text
            UserForm1.CommandButton1.Caption = "Clock-in"
            UserForm1.ComboBox1 = Empty
            Set Rng = .Range("A2:F" & .Cells(Rows.Count, 1).End(xlUp).Row)
                For Each cell In Rng.Cells
                        With UserForm1.ListBox1
                            .AddItem cell.Value
                            .List(.ListCount - 1, 1) = cell.Offset(0, 1).Value
                            .List(.ListCount - 1, 2) = cell.Offset(0, 2).Value
                            .List(.ListCount - 1, 3) = cell.Offset(0, 3).Value
                            .List(.ListCount - 1, 4) = cell.Offset(0, 4).Value
                            .List(.ListCount - 1, 5) = cell.Offset(0, 5).Value
                            .List(.ListCount - 1, 6) = cell.Offset(0, 6).Value
                        End With
                'Fim do Laço
        End With
    End With
End If

End Sub

Cadê o final dos laços Loops? Por favor revise sua rótina!
http://www.databison.com/vba-for-loop-f ... h-in-next/

Att

 
Postado : 27/01/2015 2:15 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Eu vi e ia dizer as mesmas coisas...
Tem End Withs a mais e tem um For Each sem um Next..

Sugestão, volte à rotina original e comece de novo...

FF

 
Postado : 27/01/2015 2:20 pm
(@finaljustice)
Posts: 91
Estimable Member
Topic starter
 
Sub clockit()
If UserForm1.CommandButton1.Caption = "Clock-in" And UserForm1.ComboBox1 <> "" Then
            UserForm1.ListBox1 = Clear
            With ThisWorkbook.Worksheets("Control")
            lastentry = .Range("D" & .Cells(.Rows.Count, 1).End(xlUp).Row + 1).Address
            .Range(lastentry).Value = UserForm1.TextBox4.Text
            .Range(lastentry).Offset(0, -2) = UserForm1.TextBox2.Text
            .Range(lastentry).Offset(0, -3) = UserForm1.TextBox1.Text
            .Range(lastentry).Offset(0, -1) = UserForm1.ComboBox1.Text
            UserForm1.CommandButton1.Caption = "Clock-out"
            Set Rng = .Range("A1:F" & .Cells(Rows.Count, 1).End(xlUp).Row)
            UserForm1.ListBox1.ColumnCount = 6
                
                For Each cell In Rng.Cells
                With UserForm1.ListBox1
                    .AddItem cell.Value
                    .List(.ListCount - 1, 1) = cell.Offset(0, 1).Value
                    .List(.ListCount - 1, 2) = cell.Offset(0, 2).Value
                    .List(.ListCount - 1, 3) = cell.Offset(0, 3).Value
                    .List(.ListCount - 1, 4) = cell.Offset(0, 4).Value
                    .List(.ListCount - 1, 5) = cell.Offset(0, 5).Value
                    .List(.ListCount - 1, 6) = cell.Offset(0, 6).Value
                End With
                Next cell
            End With
            
       
            
          
ElseIf UserForm1.CommandButton1.Caption = "Clock-out" And UserForm1.ComboBox1 <> "" Then
        UserForm1.ListBox1 = Clear
        With ThisWorkbook.Worksheets("Control")
        .Range(lastentry).Offset(0, 1) = UserForm1.TextBox4.Text
        UserForm1.CommandButton1.Caption = "Clock-in"
        UserForm1.ComboBox1 = Empty
        Set Rng = .Range("A1:F" & .Cells(Rows.Count, 1).End(xlUp).Row)
        UserForm1.ListBox1.ColumnCount = 6
                For Each cell In Rng.Cells
                With UserForm1.ListBox1
                    .AddItem cell.Value
                    .List(.ListCount - 1, 1) = cell.Offset(0, 1).Value
                    .List(.ListCount - 1, 2) = cell.Offset(0, 2).Value
                    .List(.ListCount - 1, 3) = cell.Offset(0, 3).Value
                    .List(.ListCount - 1, 4) = cell.Offset(0, 4).Value
                    .List(.ListCount - 1, 5) = cell.Offset(0, 5).Value
                    .List(.ListCount - 1, 6) = cell.Offset(0, 6).Value
                End With
                Next cell
       
        End With

End If


End Sub
 
Postado : 27/01/2015 2:44 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Esse parece que funfa....

 
Postado : 27/01/2015 2:49 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Regras do forum:

Upload
Devido a ultrapassagem da marca de 1,5Gb de armazenamento de arquivos na hospedagem do Planilhando, limitaremos o tamanho de cada arquivo para 2Mb sendo obrigatório o uso dos formatos .zip - .rar - .ice visto a gratuidade e não geração de recursos para bancar o site.

Assim sendo, seu anexo foi compactado.

Por favor leia as regras (link na minha assinatura), e passe a compactar todos os seus anexos.

Obrigado,

Fernando

 
Postado : 27/01/2015 3:07 pm
(@finaljustice)
Posts: 91
Estimable Member
Topic starter
 

Regras do forum:

Upload
Devido a ultrapassagem da marca de 1,5Gb de armazenamento de arquivos na hospedagem do Planilhando, limitaremos o tamanho de cada arquivo para 2Mb sendo obrigatório o uso dos formatos .zip - .rar - .ice visto a gratuidade e não geração de recursos para bancar o site.

Assim sendo, seu anexo foi compactado.

Por favor leia as regras (link na minha assinatura), e passe a compactar todos os seus anexos.

Obrigado,

Fernando

Ops! Mals

 
Postado : 27/01/2015 3:24 pm